admin管理员组文章数量:1334183
Briefly: The main idea is that I have a website with integrated Google Analytics 4 (GA4) and an independent widget integrated into this website, that also has GA4. As the result, events are sent to both trackers. How I can isolate that from each other?
Detailed: Have 2 react web apps. One is the parent-website and the other is integrated in it widget (made as react app that is built with Webpack into 2 files - js and css). This widget can be integrated to any website with script tag and css link. And this widget needs to have Google Analytics. But a parent-website can also have integrated Google Analytics. If this parent-website has Universal Analytics, it is ok, sent events are isolated, but if both have new GA4 troubles have place.
I've tried to integrate GA to both [test] apps with the help of react-ga4 library. As the result, both tracker accounts getting all events sent from widget and parent-website. And also tried to use in parent-website manually added script tag and in widget app react-ga4 library. Also all events go everywhere. Inspect
Then I've tried to add GA4 scripts manually and have two configs for two trackers. The same happens - all events go to both trackers.
The main question how to isolate events sending?
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src=";
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "TRACKING_ID_1");
</script>
<!-- Global site tag 2 (gtag.js) - Google Analytics -->
<script
async
src=";
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "TRACKING_ID_2");
</script>
Briefly: The main idea is that I have a website with integrated Google Analytics 4 (GA4) and an independent widget integrated into this website, that also has GA4. As the result, events are sent to both trackers. How I can isolate that from each other?
Detailed: Have 2 react web apps. One is the parent-website and the other is integrated in it widget (made as react app that is built with Webpack into 2 files - js and css). This widget can be integrated to any website with script tag and css link. And this widget needs to have Google Analytics. But a parent-website can also have integrated Google Analytics. If this parent-website has Universal Analytics, it is ok, sent events are isolated, but if both have new GA4 troubles have place.
I've tried to integrate GA to both [test] apps with the help of react-ga4 library. As the result, both tracker accounts getting all events sent from widget and parent-website. And also tried to use in parent-website manually added script tag and in widget app react-ga4 library. Also all events go everywhere. Inspect
Then I've tried to add GA4 scripts manually and have two configs for two trackers. The same happens - all events go to both trackers.
The main question how to isolate events sending?
<!-- Global site tag (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager./gtag/js?id=TRACKING_ID_1"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "TRACKING_ID_1");
</script>
<!-- Global site tag 2 (gtag.js) - Google Analytics -->
<script
async
src="https://www.googletagmanager./gtag/js?id=TRACKING_ID_2"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "TRACKING_ID_2");
</script>
Share
Improve this question
edited Jul 4, 2023 at 6:25
CommunityBot
11 silver badge
asked Aug 25, 2022 at 6:59
Iri.S.M.Iri.S.M.
431 silver badge4 bronze badges
1 Answer
Reset to default 9I think you need to modify your gtag event code a bit.
Please take a took about this docuemnt.
gtag('event', 'sign_in', { 'send_to': 'G-XXXXXX-2' });
The main idea is adding a parameter call send_to
and ask the event only sent to the tracking id.
And if you need to config multiple tracking id.
You can just config second tracker
No need add the <script>
again
<script async src="https://www.googletagmanager./gtag/js?id=TRACKING_ID_1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
gtag("config", "TRACKING_ID_1");
gtag("config", "TRACKING_ID_2");
</script>
本文标签: javascriptMultiple Google Analytics 4 script trackers for one pageStack Overflow
版权声明:本文标题:javascript - Multiple Google Analytics 4 script trackers for one page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742310565a2450784.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论