partytown
partytown copied to clipboard
Enable to push back 'forwarded' Array values on main thread
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 :)
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) |
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?
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).
@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.
@DanBeckDev hey! Could you pay attention to the @sylvain-a's question? Merci 🙏
This PR is old, so I'm closing this for now. Feel free to re-open it if it's still valid. Thanks.