Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Tracker: new setPageViewId function to override the pageviewid and not have it auto generated #17655

Merged
merged 4 commits into from Jun 9, 2021

Conversation

JE4GLE
Copy link
Contributor

@JE4GLE JE4GLE commented Jun 8, 2021

Description:

This Pull Request solves the issue mentioned in the following issue: #16942

It would allow for a combination of the PHP tracker (to track 100% of the PageViews) and the JavaScript tracker (to track screen size, plugins, …) by first generating a page view id on the PHP side and setting it after page generation using JavaScript.

Review

  • Functional review done
  • Potential edge cases thought about (behavior of the code with strange input, with strange internal state or possible interactions with other Matomo subsystems)
  • Usability review done (is anything maybe unclear or think about anything that would cause people to reach out to support)
  • Security review done see checklist
  • Code review done
  • Tests were added if useful/possible
  • Reviewed for breaking changes
  • Developer changelog updated if needed
  • Documentation added if needed
  • Existing documentation updated if needed

@diosmosis
Copy link
Member

Hi @JE4GLE, thanks for taking the time to create this pull request! Currently the jslint tests are failing, I believe because the new method is not currently in the list here: https://github.com/matomo-org/matomo/blob/4.x-dev/js/piwik.js#L66. Would you be able to add it?

@diosmosis
Copy link
Member

build js

@diosmosis
Copy link
Member

Hmm, looks like the tracker javascript building workflow isn't working on this PR. I'll build it manually before merging.

@diosmosis
Copy link
Member

@JE4GLE Looks like this change would create a regression, actually. logPageview() generates a pageview id, and is supposed to generate a new one on every subsequent call so new pageviews have new IDs. Now, however, the pageview ID is only set on the first call, then since it's already set at the second call, nothing changes.

This could be fixed pretty easily by having another variable like configIdPageViewSetManually that is set to true in setPageViewId(). Then we check this in logPageview(). However I'm not sure if this causes problems for your usecase. Would you be able to change the pageview ID and still have it determined by the PHP tracker code you're using (assuming I understand the use case correctly)?

@JE4GLE
Copy link
Contributor Author

JE4GLE commented Jun 9, 2021

@diosmosis My use case would be:

  1. Create a pageview request with a pageview ID in PHP and place it in the HTML code, before page generation
  2. After the page has loaded, the JavaScript code will then read this ID in the HTML code and set it manually
  3. Send the pageview again using JavaScript, but this time including additional data from JavaScript

Unfortunately I don't quite understand, why the pageview ID would change during one page visit. In my understanding, the user visits a page and a pageview ID is generated, which will stay the same, until the user reloads the page or goes to another one.

Anyways, here's your proposed change:

@diosmosis
Copy link
Member

@JE4GLE

Unfortunately I don't quite understand, why the pageview ID would change during one page visit. In my understanding, the user visits a page and a pageview ID is generated, which will stay the same, until the user reloads the page or goes to another one.

After logPageview() is called we expect the pageview to be over, and subsequent calls to use a different ID. In a normal website where you click links that load new pages, this wouldn't be needed, but for single page apps where the page never reloads, and the app calls logPageview() itself multiple times without the page reloading, this change would break things.

I guess if you're expecting only one pageview before a new page is loaded or the current page is reloaded, then I suppose you wouldn't be affected by this.

@diosmosis
Copy link
Member

The change looks good now and the build passes. Thanks again for taking the trouble to make the PR and apply fixes @JE4GLE!

@diosmosis diosmosis merged commit 13f7d9a into matomo-org:4.x-dev Jun 9, 2021
@diosmosis diosmosis added this to the 4.4.0 milestone Jun 9, 2021
@mattab mattab changed the title Add option to set page view id manually JS Tracker: new setPageViewId function to override the pageviewid and not have it auto generated Jul 27, 2021
@mattab mattab added the c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself. label Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Platform For Matomo platform changes that aren't impacting any of our APIs but improve the core itself.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants