chore(analytics) | Improve traffic source retention on cross domain measurements#49
Merged
cgarrovillo merged 6 commits intomasterfrom Sep 6, 2024
Merged
chore(analytics) | Improve traffic source retention on cross domain measurements#49cgarrovillo merged 6 commits intomasterfrom
cgarrovillo merged 6 commits intomasterfrom
Conversation
ShannonTJ
reviewed
Sep 6, 2024
| // When the referrer is unavailable (ie. direct visit), the web-app | ||
| // should not inject and GA4 defaults to the default behaviour. | ||
| const referrer = document.referrer || ""; | ||
| if (referrer) { |
There was a problem hiding this comment.
Do you also need to check if referrer !== ""
?
Member
Author
There was a problem hiding this comment.
hmm I think thats covered already by the truthiness check
There was a problem hiding this comment.
Just checking, since we do that check for the cookie up above.
Member
Author
There was a problem hiding this comment.
Hmm cant remember exactly why we did that for the cookie tbh lol but I think theres a reason for cookies..
ShannonTJ
reviewed
Sep 6, 2024
ShannonTJ
approved these changes
Sep 6, 2024
adnankarim-showpass
approved these changes
Sep 6, 2024
abhinavchawla13
approved these changes
Sep 6, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the change
This aims to mitigate an issue in cross-domain measurements where the original traffic source is not maintained throughout the entire session despite matching client_id/session_id.
I did this by keeping track of the parent documents referrer, which is used by GA4 as the traffic source
How to test
Use this PR on the web-app https://bitbucket.org/showpass/web-app/pull-requests/6734
GIVEN a site with a different domain than showpass
AND an iframe of showpass displayed through the showpass plugin
WHEN you open up the iframe
THEN you should see in network devtools that the referrer for the first /collect call to analytics.google.com is that the referrer is the parent domain.
GIVEN a site with a different domain than showpass
AND an iframe of showpass displayed through the showpass plugin
WHEN you visit the site through google search, or through another domain
AND you open up the iframe
THEN you should see in network devtools that the referrer for the first /collect call to analytics.google.com is that the referrer is the original site you first landed on. For example, exampleA.com → exampleB.com → showpass.com → add to cart, the referrer is exampleA.com.
You can see the field on network devtools /collect call payload under the _dr parameter