feat: add support for ga4 cross-domain measurements #21
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.
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.* :^)