BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.85k stars 426 forks source link

[🐞] GA4 is not working properly for Partytown with Astro #457

Open THILAK6 opened 10 months ago

THILAK6 commented 10 months ago

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

gioboa commented 10 months ago

Hi, can you explain better "partially works" please? Do you have any error?

thejackshelton commented 10 months ago

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?

lilnasy commented 8 months ago

Hi, this issue was reported on the astro repo with a reproduction.

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.

THILAK6 commented 8 months ago

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.

gioboa commented 6 months ago

@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.