Git Product home page Git Product logo

Comments (12)

mrakus-sofomo avatar mrakus-sofomo commented on July 18, 2024 2

This is because the Playwright component mounts a snippet to the header, this snippet, only checks once for the existence of the text/partytown scripts, when the document is loaded. The logic does not rerun when page transition happens.
https://github.com/BuilderIO/partytown/blob/main/src/lib/main/snippet.ts#L156

Edit: I've scratched around a bit more and it seems that the worker uses requestAnimationFrame, to detect the next scripts. I'll try to debug it some more, I'm annoyed by this bug, especially since it's been open for so long.

from partytown.

valse avatar valse commented on July 18, 2024 1

Hi, I finally found how to use GA with Partytown and Next.js.... here my post about it: I'd like to try with GTM too.

from partytown.

valse avatar valse commented on July 18, 2024

Hi, I have the same question too: I successfully loaded the GTM script on my custom Next.js Document page and, at start, the pageview event is triggered as expected.

I tried, then, to push the pageview event client side, listening on "routeChangeComplete" router event but the command is never forwarded to the service worker:

useEffect(() => {
    const pageview = (url) => {
      dataLayer.push({
        event: "pageview",
        page: url,
      })
    }

    router.events.on("routeChangeComplete", pageview)

    return () => {
      router.events.off("routeChangeComplete", pageview)
    }
}, [router.events])

from partytown.

danielroe avatar danielroe commented on July 18, 2024

We're encountering the same with Nuxt. I think implementing with MutationObserver might be a straightforward approach?

from partytown.

itsmnthn avatar itsmnthn commented on July 18, 2024

I faced this same issue while implementing this with Nuxt2. Initial event works well but using window.dataLayer.push(event) doesn't trigger GTM request for that event.

I've created simple implementation here nuxt2-partytown-demo

If this issue is fixed then I'm planning to write a module/plugin for Nuxt2 to implement Partytown

from partytown.

itsmnthn avatar itsmnthn commented on July 18, 2024

I ran gtag integration test locally and it seems button click is not sending event as it suppose to send { event: 'button-click', from: 'partytown' }

test/integration/gtag at https://github.com/BuilderIO/partytown/blob/main/tests/integrations/gtm/index.html`

Also tried live test https://partytown.builder.io/tests/integrations/gtm/ with same problem.

Is this expected behaviour and I am not understanding something or there is problem?

from partytown.

CruScanlan avatar CruScanlan commented on July 18, 2024

I am getting the same issue. I cannot find a way to send a page view event to the Partytown GTM script from the main thread in Next.js.

from partytown.

itsmnthn avatar itsmnthn commented on July 18, 2024

Check this demo nuxt2-partytown-demo I tried using hidden input on main thread and dispatchEvent('change') on button click and listen the same input change event in text/partytown gtag script and use gtag('pageView', 'about') but with no luck.

doing window.dataLayer.push inside partytown script where gtag is initialised works only once, letter it just doesn't send new event after it.

from partytown.

wardpeet avatar wardpeet commented on July 18, 2024

@adamdbradley what's would be the correct approach here to help implement?

  1. Create mutation observer that listens to newly created script tags with type text/partytown and route them through partytown.
  2. Create a function that you can call to inject partytown tags?

One would be the most automated one, where you don't have to think about implementation details as a end-user. The second option would be more on the framework side, where you can do the logic with a Script component.

from partytown.

gioboa avatar gioboa commented on July 18, 2024

Thanks for your help @mrakus-sofomo
let's try to solve this issue

from partytown.

mrakus-sofomo avatar mrakus-sofomo commented on July 18, 2024

@gioboa Is this issue still present in nextjs worker script?
https://nextjs.org/docs/pages/building-your-application/optimizing/scripts#offloading-scripts-to-a-web-worker-experimental

from partytown.

gioboa avatar gioboa commented on July 18, 2024

@gioboa Is this issue still present in nextjs worker script? https://nextjs.org/docs/pages/building-your-application/optimizing/scripts#offloading-scripts-to-a-web-worker-experimental

I guess so. I didn't solve it yet

from partytown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.