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

[🐞] Google Analytics Events aren't fired #519

Open mrxbox98 opened 6 months ago

mrxbox98 commented 6 months ago

Describe the bug

After setting up Google Analytics with Partytown (user analytics are working) events such as a purchase are not pushed to google analytics.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-heabie?file=src%2Froutes%2F%2Blayout.svelte

Steps to reproduce

Setup google analytics with partytown properly. Push an event like

window.gtag("event", "purchase", {
        DATA
    });

Browser Info

All

Additional Information

When not using Partytown the events are properly pushed.

gioboa commented 6 months ago

I see, thanks for your report. Can you create a PR with a failing test for this issue? A vanilla JS one will be perfect.

gioboa commented 6 months ago

Did you use forwarding-events API ?

mrxbox98 commented 6 months ago

Did you use forwarding-events API ?

Yes

<script>
        // Forward the necessary functions to the web worker layer
        partytown = {
            forward: ['dataLayer.push', 'gtag'],
        };
    </script>
gioboa commented 6 months ago

A specific test for this issue will be awesome to solve this problem

lknlknim commented 6 months ago

Did you proxy the url to resolve CORS?

mrxbox98 commented 6 months ago

A specific test for this issue will be awesome to solve this problem

Not entirely sure how to write a test for it since I'm unfamiliar with this repo. https://stackblitz.com/edit/sveltejs-kit-template-default-heabie?file=src%2Froutes%2F%2Blayout.svelte should mostly replicate it.

Did you proxy the url to resolve CORS?

Everything else google analytics works so I don't think its CORS

mrxbox98 commented 6 months ago

Update: I just received an event in Google Analytics with this config so it might be something else that I have configured incorrectly. I'll give it a week to see what happens.

gioboa commented 6 months ago

GA doesn't update data in real-time You can have more info here