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.88k stars 427 forks source link

Events not firing in Segment using Partytown #409

Open vitormalencar opened 1 year ago

vitormalencar commented 1 year ago

Description:

Hey Party Town team,

I'm having some trouble getting events to fire in Segment using Partytown. Here's a snippet of the code I'm using to load the Segment snippet in my app:

{!isServer() && !window?.analytics && (
  <Script
    dangerouslySetInnerHTML={{
      __html: renderSegmentSnippet(),
    }}
  />
)}

And here's how I'm setting up Partytown to forward events to Segment:

<Partytown forward={['dataLayer.push']} />

However, when I check the Segment dashboard, no events are being recorded. I've checked my browser console for errors and made sure that my Segment implementation is set up correctly, but I'm still not sure what's going wrong.

erickcelio commented 1 year ago

Hey, I'm trying to implement Partytown with Next too, I'm still facing some issues but some things that I've found in the last few days probably should add a few events to the forward because the segment uses the load event to really connect with your segment account and the other's to send the events and another thing that I'm not sure but It's how works for me I've to use the html script instead the next/script, try to use them and see if that's works for you

<Partytown
  debug={true}
  forward={[
    'dataLayer.push',
    'analytics.load',
    'analytics.trackSubmit',
    'analytics.trackClick',
    'analytics.trackLink',
    'analytics.trackForm',
    'analytics.pageview',
    'analytics.identify',
    'analytics.reset',
    'analytics.group',
    'analytics.track',
    'analytics.ready',
    'analytics.alias',
    'analytics.debug',
    'analytics.page',
    'analytics.once',
    'analytics.off',
    'analytics.on',
    'analytics.addSourceMiddleware',
    'analytics.addIntegrationMiddleware',
    'analytics.setAnonymousId',
    'analytics.addDestinationMiddleware'
  ]}
/>
  <script
    type="text/partytown"
    dangerouslySetInnerHTML={{ __html: renderSegmentSnippet() }}
  />