partytown
partytown copied to clipboard
[🐞] GA4 is not working properly for Partytown with Astro
Describe the bug
We are attempting to use Partytown to track Google Analytics within an Astro TypeScript project. However, we are encountering intermittent issues where Partytown partially works. It sometimes functions as expected, but at other times, it doesn't. We have reviewed the examples provided on the Partytown website and are still facing these challenges.
Reproduction
A sample Astro project with partytown integration
Steps to reproduce
We have added this code in the layout of the project
<script type="text/partytown" src="https://www.googletagmanager.com/gtag/js?id=YOUR-ID-HERE"></script>
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'YOUR-ID-HERE');
</script>
Browser Info
Chrome, Firefox
Additional Information
No response
Hi, can you explain better "partially works" please? Do you have any error?
Hey, like Giorgio mentioned, can we see an error here? And what functionality isn't working as expected?
Also could you explain where you got the 2nd script from?
Hi, this issue was reported on the astro repo with a reproduction.
- https://github.com/withastro/astro/issues/8862
Quick summary - the error is not a javascript, or web error but specifically firefox, and would probably happen on any page using partytown that also uses the history API.
Hi, Sorry for the very late reply. What we mean by partially works is, not every event is recorded in GA4. Let's if the page is viewed 100 times, in GA4 we could see only 10 or 20 views. If we are not using partytown and use GA4 directly we could see all 100 page views in GA4.
@THILAK6 do you have errors in the console? we solved a problem with Firefox ( #511 ) but you mentioned Chrome too so I don't think it solves your problem.