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.98k stars 428 forks source link

[GatsbyJS + GTM] Events not being sent when pushed to DataLayer #44

Closed igorbrasileiro closed 2 years ago

igorbrasileiro commented 2 years ago

Hi, 👋 !

I'm trying to integrate the Partytown + Gatsby, but I'm facing some problems sending events.

Basically, I added the GTM and Partytown components in the head. Inside the components, call window.dataLayer.push. But I realized that just send page_view events.

// gatsby-ssr.js
export const onRenderBody = ({ setHeadComponents }) => {
  setHeadComponents([
    <GoogleTagManager
      key="gtm"
      containerId={storeConfig.analytics.gtmContainerId}
      enablePartytown
    />,
    <Partytown key="party" />,
  ])
}
// sending events to dataLayer
useAnalyticsEvent((event) => {
  console.log('EVENT', event)
  window.dataLayer.push(event)
})

I'm missing something? I tried to use the debug flag, but I didn't see the console.logs 😞 .

For more information:

Partytown Version: 0.0.29 Gatsby Version: 3.14.3

igorbrasileiro commented 2 years ago

I will close this issue because the problem was with the GTM settings.