Skip to content

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

Open
filiphsps wants to merge 1 commit intoinstantcommerce:masterfrom
filiphsps:feat/ga4-crossdomain
Open

feat: add support for ga4 cross-domain measurements#21
filiphsps wants to merge 1 commit intoinstantcommerce:masterfrom
filiphsps:feat/ga4-crossdomain

Conversation

@filiphsps
Copy link
Copy Markdown

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