partytown icon indicating copy to clipboard operation
partytown copied to clipboard

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

Open THILAK6 opened this issue 1 year ago • 5 comments

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

THILAK6 avatar Sep 01 '23 06:09 THILAK6

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

gioboa avatar Sep 01 '23 10:09 gioboa

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?

thejackshelton avatar Sep 01 '23 16:09 thejackshelton

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.

lilnasy avatar Oct 31 '23 16:10 lilnasy

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 avatar Nov 02 '23 06:11 THILAK6

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

gioboa avatar Dec 29 '23 13:12 gioboa