snowplow-javascript-tracker
snowplow-javascript-tracker copied to clipboard
Add tab identifier on web_page context. Fix #815
Add tab identifier in the web_page context
As discussed in #815 it would be useful to add a tab identifier to further the analysis capabilities.
We will enrich the webpage schema with a tabId attribute which aims to identify the tab the user was in when he navigated the site. (PR incoming for the iglu repository)
The PR also adds the tracker.getTabId()
method on the public API.
Technical implementation:
The tab identifier can be implemented using the sessionStorage API that provides access to a ‘session’ type persistence on the current tab.
By using the API we should understand the benefits/limitations it provides:
- Persistence is valid for the same origin by default. Meaning different origins will have different tab identifiers even if they were navigated from the same tab.
- If the tab is closed, the identifier will be lost.
- If the user continues his navigation on different origins and comes back again on the origin the identifier was initialised, on the same tab, the tab identifier will be the same.
- If the user refreshes the page, the tab identifier will be the same.
Compatibility:
The compatibility is proper for our trackers based on caniuse.
Multi-tracker behaviour:
The tabId attribute will be the same for the different Snowplow trackers that might be initialised on the page.
Anonymous tracking:
This value should not be able to be used to identify anonymous users by stitching the tab identifier with a later non-anonymous usage of the tracker. On anonymous and stateless behaviour, a random uuid is returned every time. E.g. I browse the site with anonymous tracking enabled. After some time I enable tracking to function properly. If I am on the same tab, the analyst can stitch the tab identifier and correlate the anonymous with the recognised user.
Storage behaviour:
This value depends on user allowing storage in the storage strategy. Additionally it can conceptually be classified in the same strategy as “localStorage“ since both these structures are implementing the same Web Storage API and mechanisms.
Documentation
Will discuss what needs to change on the webPage context section.
Notes
Additional minor fixes:
- A few typos.
- Split the storage helpers to their own file.
- Add the correct return type for
tracker.getPageViewId()
The last changes look good! Lets just wait for the integration tests to pass and I think we are good.
Speaking of integration tests, there are a few places where the old schema version is referenced, I think those will keep failing even when the schema is available on Iglu central. See here for instance – btw, at this place, if you have a bit of time, it would be nice to also add a short integration test case for the tabId
in addition to the page view ID test. It's not super important, but it'd be nice to have that!
BundleMon
Files added (6)
Status | Path | Size | Limits |
---|---|---|---|
:white_check_mark: | libraries/browser-tracker-core/dist/index.mod ule.js |
+24.52KB | 25KB / +10% |
:white_check_mark: | trackers/javascript-tracker/dist/sp.js |
+23.8KB | 25KB / +10% |
:white_check_mark: | trackers/javascript-tracker/dist/sp.lite.js |
+14.53KB | 15KB / +10% |
:white_check_mark: | trackers/browser-tracker/dist/index.umd.min.j s |
+14.4KB | 15KB / +10% |
:white_check_mark: | libraries/tracker-core/dist/index.module.js |
+13.35KB | 15KB / +10% |
:white_check_mark: | trackers/browser-tracker/dist/index.module.js |
+3.46KB | 5KB / +10% |
Total files change +94.06KB 0%
Final result: :white_check_mark:
View report in BundleMon website ➡️