Comments (11)
wow! was about to say the same @hoebbelsB . Thanks for your explanation, I don't have to do one. I think this can be considered as bug as it is not documented that it is how it works. On my end, altho similar to the workaround that you've done, I put the window['global']
assignment on my gtm scripts configuration in index.html
directly. So now it looks like this:
<script type="text/partytown">
window.initGoogleTagManager = function(tagManagerId) {
(function (w, d, s, l, i) {
<!-- Set global property of window for gtm to work -->
w['global'] = d;
w[l] = w[l] || []; w[l].push({
'gtm.start':
new Date().getTime(), event: 'gtm.js'
}); var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', tagManagerId);
}
</script>
Also, on my end the resolveSendBeaconRequestParameters
in parytown configuration looks like this:
partytown = {
...,
resolveSendBeaconRequestParameters: function (url) {
return url.hostname.includes('analytics.google') ||
url.hostname.includes('google-analytics')
? { keepalive: false }
: {};
},
}
This is because, I noticed that the request hostname contains that string.
With all these in place, I was able to see the collect
request on the Network tab
now.
I would still need to test more of it, because I still see some delays on the requests, but I'm happy as you are to see that it works now with that workaround.
If this is intended behavior, I think it should be documented in the GTM x Partytown docs. It is important to note that when implementing GTM within Partytown, the analytics should work. If this is the case, I can close this issue with that workaround, but only if it is added to the documentation.
from partytown.
What is the best way to configure this to no longer be an issue?
{ ... resolveSendBeaconRequestParameters: function (url, location) { if (url.pathname.includes('collect')) { return {keepalive: false}; } return {}; } }
I think we have it configured as
resolveSendBeaconRequestParameters: function (url) {
if (url.hostname.includes('google-analytics')) {
return { keepalive: false };
}
},
That they are not being sent at all is a different story, though. I'm also struggling with an integration right now. As of now i've figured out that the gtm.js
event is not properly forwarded to the gtm script, suppressing its functionality.
For whatever reason, the dataLayer
property gets swapped out in the gtm script.
When the gtm.js scripts gets initialized, the dataLayer
still contains the gtm.js
event, which is correct.
However, before initializing, the dataLayer
property now does not contain the gtm.js
event anymore, but instead some ids and the name dataLayer
.
At least for our current state, this is the reason why nothing gets actually kicked off.
Btw. if I manually switch out the dataLayer
to [{ event: 'gtm.js', 'gtm.start': new Date().getTime() }]
, it will properly kick off all events and download other third parties.
cc @gioboa
from partytown.
@replete we ran into the same issue and figured out that we need to configure keepalive: false
for the collect requests: #555
from partytown.
@kyudorimj @gioboa I just figured out, that gtm internally accesses the window['global']
property.
This is not a known property to the worker as it seems, but it looks like it would be aware of the type to return. So what partytown then does is to create a new Window
object for that accessor.
After this, the dataLayer
object is reset. And it looks like this is happening for each nested gtm container.
I also found a workaround for this. We essentially just set the global
property on window
upfront in the index.html file.
<script type="text/partytown">
(function() {
window.global = document;
})();
</script>
With this in place, all scripts are loaded and all gtm tags are working just fine.
Not sure if this is considered as bug, or intended behavior. Going to investigate a bit more about this. It might also be possible to introduce a GetterHook
in order to achieve a similar behavior. For now I'm happy that things are working again 😓
from partytown.
I've come across this after testing out partytown myself with GTM. Even on a small hyper optimized website, and FYI: I found that the collect?
GTM POST payload does not happen until over 5 seconds, even on subsequent visits, which for me means its not reliable for analytics like this.
EDIT 24/04/24: I've been investigating this and I've discovered this happens even normally, without partytown.
I have since learned more about sendBeacon()
and using fetch()
with keepalive:true
(to prevent cancellation of request after window navigation and have observed GTM using both sendBeacon() and fetch() with or without partytown.
GTM.js is a complex script and at this point I'm going to leave this alone and return to this later. I think realistically if you are going to use partytown with GTM on an important site, you need a way to test if all the expected events are happening.
from partytown.
What is the best way to configure this to no longer be an issue?
{
...
resolveSendBeaconRequestParameters: function (url, location) {
if (url.pathname.includes('collect')) {
return {keepalive: false};
}
return {};
}
}
from partytown.
@hoebbelsB I was wondering about something similar last night but after some hours deep diving the GTM/partytown stack I decided GTM.js was very complicated and for now just switched partytown off. This is great info and I'll continue my own investigations at some point. I feel like I need to setup a temporary analytics endpoint and run alongside partytown so I can compare data on live for a few days before I can fully trust using partytown for analytics. It seems so very close, thanks for the update, I'll report back when I figure out more.
@kyudorimj Apologies for missing your comment, I also deleted a few comments to clean up the thread as I realized during my investigations I wasn't having quite the same issues. I'll come back to this but ultimately GTM is very complicated and I saw both fetch() and sendBeacon() being used, so there were multiple red herrings.
from partytown.
Indeed, @replete. I also discovered that this collect?
requests was sent via sendBeacon
while running through partytown
, resulting in console errors during the request.
from partytown.
figured out that we need to configure
keepalive: false
for the collect requests: #555
great work @hoebbelsB , tho on my end there's no collect
request at all when scripts were ran through partytown.
from partytown.
I've come across this after testing out partytown myself with GTM. Even on a small hyper optimized website, and FYI: I found that the
collect?
GTM POST payload does not happen until over 5 seconds, even on subsequent visits, which for me means its not reliable for analytics like this.
@replete , can you share us your GTM configuration?
from partytown.
@kyudorimj Thanks for the solution! I was trying to integrate partytown on redBus app and the collect calls are fired consistently but still the page_view
and onLoad
events are not fired, also I am not able to see those calls in the network tab.
My integration looks like this:
<script type="text/javascript">
partytown = {
forward: ["dataLayer.push","gtag"],
lib: "/activities/public/scripts/~partytown/",
resolveSendBeaconRequestParameters: function (url) {
return url.hostname.includes('analytics.google') ||
url.hostname.includes('google-analytics')
? { keepalive: 0 }
: {};
},
};
</script>
<script async type="module" src="/activities/public/scripts/~partytown/partytown.js"/></script>
<script type="text/partytown">
(function() {
window.global = document;
})();
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer',myTag);
</script>
The gtag is not reaching the below method call when partytown is enabled
Does anyone have solution related to page_view events?
from partytown.
Related Issues (20)
- [🐞]partytown throws error in chrome developer console and not able to connect to GTM preview mode HOT 13
- [🐞]404 errror throws while implementing partytown in gatsby application HOT 3
- Failed to register a ServiceWorker for scope ('https://example/~partytown/') with script ('https://example.com/~partytown/partytown-sw.js'): The script resource is behind a redirect, which is disallowed. HOT 1
- Partytown integration with Astro makes over 10'000 proxytown requests on page load[🐞] HOT 2
- [🐞] Google Tag Manager NextJS forward events coming as blank []
- [🐞] Cannot read property 'Error' of null
- [🐞] Proxy object could not be cloned HOT 1
- [🐞] Firefox: 404 partytown-sandbox-sw.html HOT 1
- [🐞] Firefox: Private Browsing for external Scripts HOT 1
- [🐞] Objects and object properties can't be forwarded HOT 2
- [🐞]in statement is not reliable when running through partytown
- [📖] resolveSendBeaconRequestParameters missing in docs and React types HOT 1
- [🐞]: forwarding gtm dataLayer.push breaks immediate dataLayer pushes HOT 3
- [🐞] page_view and on_load events are not firing in GA4
- [🐞] Intercom does not work with party town HOT 1
- [🐞]user_engagement is not working in GA4
- [🐞] AppsFlyer Smart Banner does not work
- [🐞] How to setup correctly partytown for astro.js HOT 1
- [🐞] GTM doesnt work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from partytown.