-
Notifications
You must be signed in to change notification settings - Fork 222
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
Add an option to generate the page view ID according to changes in the page URL to account for events tracked before page views in SPAs (close #1307 and #1125) #1308
Conversation
…e page URL to account for events tracked before page views in SPAs (close #1307)
BundleMonFiles added (6)
Total files change +100.74KB 0% Final result: ✅ View report in BundleMon website ➡️ |
That was quick Matus - thanks! |
Thank you @matus-tomlein - I will be able to look into it on Monday. |
…me page regardless of whether preservePageViewIdForUrl is enabled
…age view IDs for events tracked after each other
e94ceb7
to
f0620b9
Compare
This solution should solve our current problem, and I also appreciate the options provided to further specify an appropriate strategy such as However, we are currently aiming for a deferred mode where we delay the execution of tracking events (should go live this week). In this case, we would actually fire tracking events on a new page, even though they may originate from a previous page. We do this to shorten presentation delays on interactions. With the current solution this would result in this scenario (when running in deferred mode; page view events are excluded from deferral):
We will consider to checkout this strategy in combination with performance improvements regarding the cookie strategy / expensive cookie reads/writes. As we may can get rid off the deferral mode as soon as tracking calls are less expensive. |
As an addition to my previous comment: /** This code is for demonstration purposes only */
// should also return the web page entity among the other global ones
import { getGlobalContext } from "@snowplow/browser-tracker";
const globalContext = getGlobalContext(); // could receive a tracker id as an argument
const timestamp = Date.now();
const event = { ... };
const context = [ ... ];
requestIdleCallback(() =>
trackSelfDescribingEvent({
event,
context,
globalContext,
timestamp,
});
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…e page URL to account for events tracked before page views in SPAs (close #1307 and #1125) PR #1308 * Add an option to generate the page view ID according to changes in the page URL to account for events tracked before page views in SPAs (close #1307) * Generate a new page view ID on the second page view tracked on the same page regardless of whether preservePageViewIdForUrl is enabled * Handle multiple trackers with shared state such that they share the page view IDs for events tracked after each other
…e page URL to account for events tracked before page views in SPAs (close #1307 and #1125) PR #1308 * Add an option to generate the page view ID according to changes in the page URL to account for events tracked before page views in SPAs (close #1307) * Generate a new page view ID on the second page view tracked on the same page regardless of whether preservePageViewIdForUrl is enabled * Handle multiple trackers with shared state such that they share the page view IDs for events tracked after each other
Issue #1307
Problem
In SPAs, as the user is navigating through pages, it may happen that certain events belonging to a page are tracked before the page view event. For example, auto-tracked events relating to the experiment selection in A/B testing may be tracked before the actual page view.
We would want these events to share the same page view ID as the page view event that is tracked for the same page URL even though that is tracked later.
Currently the page view ID is generated at the time of the page view event, so all events tracked before it have a different page view ID (this is not the case for the very first page view event, but is for the second and subsequent events).
Solution
This PR adds an option called
preservePageViewIdForUrl
to the tracker configuration which has the following settings:false
(default) – keep the current behaviour (i.e., new page view ID is generated when new page view event is tracked)true
or'full'
– the page view ID will be kept the same for all page views with that exact URL (even for events tracked before the page view event).'pathname'
– the page view ID will be kept the same for all page views with the same pathname (search params or fragment may change).'pathnameAndSearch'
– the page view ID will be kept the same for all page views with the same pathname and search params (fragment may change).Thus, if this option is configured to something else than
false
, events that happen on the second page but precede the second page view will have the same page view ID as the second page view. To illustrate, it will work as follows:http://example.com/a
http://example.com/b
This PR also fixes issue #1125 which reported the problem that if two trackers are initialized on the same page, the second page view event will have different page view IDs for each of them (the first will have the same). If this new option is configured, the second page view event will have the same page view ID on both trackers.
cc @davidher-mann and @j7i – we discussed this problem on our call, would be great to get your feedback if this solution fixes the issue for you!