partytown icon indicating copy to clipboard operation
partytown copied to clipboard

Enable to push back 'forwarded' Array values on main thread

Open sylvain-a opened this issue 2 years ago • 5 comments

Hi,

This PR solve my case where some scripts running on the main thread needs to read the data that have been pushed inside the "dataLayer" array.

I've added this behavior in the mainForwardTrigger, but that might not be the best place to set this.

Thank you for your feedback, and happy to improve it :)

sylvain-a avatar Jul 08 '22 12:07 sylvain-a

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
partytown ✅ Ready (Inspect) Visit Preview Jul 8, 2022 at 0:52AM (UTC)

vercel[bot] avatar Jul 08 '22 12:07 vercel[bot]

Sorry I'm not entirely following what issue this is addressing. Would you be able to put together an example of what this fixes for Google Tag manager?

adamdbradley avatar Jul 09 '22 13:07 adamdbradley

When GTM events are executed via Partytown on the web worker the data layer is not added to the window object on the main thread. This change re-creates that, as some other 3rd party scripts rely on this existing (despite it being an anti-pattern).

DanBeckDev avatar Jul 11 '22 09:07 DanBeckDev

@adamdbradley It does not really fixes something for the execution of scripts in GTM. If I had to write a functional test (maybe derived from the gtm integration test), it would check if the data { event: 'button-click', from: 'partytown' } pushed inside dataLayer is present on the global window.dataLayer variable.

However, for my use case it solves 2 problems :

  • I have scripts that will execute on the main thread, and they (unfortunately) rely on the content of the global window.dataLayer variable. I need to set back values pushed inside this variable so they can work
  • I have selenium scripts that check the content of the dataLayer, to ensure the tracking of the website is correct. They will fail if no data is present in the window.dataLayer variable.

@DanBeckDev Thank you for the review. Do you have use cases or examples that could help to code a more general & configurable answer ? For now I don't really know how to make it more dynamic for the 'push' method.

sylvain-a avatar Jul 12 '22 07:07 sylvain-a

@DanBeckDev hey! Could you pay attention to the @sylvain-a's question? Merci 🙏

unrealhero18 avatar Jul 18 '22 07:07 unrealhero18

This PR is old, so I'm closing this for now. Feel free to re-open it if it's still valid. Thanks.

gioboa avatar Feb 24 '24 14:02 gioboa