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

feat: add support for ga4 cross-domain measurements #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

filiphsps
Copy link

This isn't nearly as straightforward as it would initially seem. Additionally, it's essentially required for some store setups to get any form of accurate attribution/data tracking at all.

Note: To get it working you'll need to include Google Analytics 4's gtag.js and make sure it gets loaded and executed before the body does. In other words, make sure it's a blocking script in the <head> tag.

(there isn't really a great way to listen for gtag being initialized and even if there was it wouldn't make sense to waste time on loading it async since the whole goal is to redirect the user anyways).

*Based on code I wrote privately for https://www.sweetsideofsweden.com now available under MIT. I pretty much had to figure out this workaround through basically reverse-engineering.

Hopefully this will save people from also having to go through that pain.* :^)

This isn't nearly as straightforward as it would initially seem.
Additionally, it's essentially required for some store setups to get
any form of accurate attribution/data tracking at all.


**Note: To get it working you'll need to include Google Analytics 4's
gtag.js and make sure it gets loaded and executed before the body does.
In other words, make sure it's a blocking script in the `<head>` tag.**
- (there isn't really a great way to listen for gtag being initialized
and even if there was it wouldn't make sense to waste time on loading
it async since the whole goal is to redirect the user anyways).


*Based on code I wrote privately for https://www.sweetsideofsweden.com
now available under MIT. I pretty much had to figure out this
workaround through basically reverse-engineering. Hopefully this will
save people from also having to go through that pain.* :^)
@filiphsps filiphsps force-pushed the feat/ga4-crossdomain branch from 88461c9 to e65a3a0 Compare July 19, 2023 00:35
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.

1 participant