Skip to content

chore(analytics) | Improve traffic source retention on cross domain measurements#49

Merged
cgarrovillo merged 6 commits intomasterfrom
SPW-12898
Sep 6, 2024
Merged

chore(analytics) | Improve traffic source retention on cross domain measurements#49
cgarrovillo merged 6 commits intomasterfrom
SPW-12898

Conversation

@cgarrovillo
Copy link
Copy Markdown
Member

@cgarrovillo cgarrovillo commented Sep 5, 2024

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.comshowpass.com → add to cart, the referrer is exampleA.com.

You can see the field on network devtools /collect call payload under the _dr parameter

@cgarrovillo cgarrovillo marked this pull request as ready for review September 6, 2024 14:57
@cgarrovillo cgarrovillo changed the title 12898 passing new parent search params chore(analytics) | Improve traffic source retention on cross domain measurements 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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also need to check if referrer !== ""
?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I think thats covered already by the truthiness check

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking, since we do that check for the cookie up above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm cant remember exactly why we did that for the cookie tbh lol but I think theres a reason for cookies..

Comment thread plugin/js/showpass-custom.js Outdated
@cgarrovillo cgarrovillo merged commit 45f2b0b into master Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants