Checking window.dataLayer in partytown thread

278 Views Asked by At

I'm trying to use partytown to run Google Analytics in a web worker. I've set up everything with the url proxies wherever necessary and now I want to check that it's all working as expected.

The issue I'm facing is that I want to inspect the events that are being pushed to the dataLayer array. In my partytown configuration I'm forwarding the dataLayer.push method correctly. I would like to log the array to see its contents after doing some actions. Is there a way to do this? If I run console.log(window.dataLayer) on the main thread it's just an empty array with the push method I'm forwarding. However, I know for a fact there is more stuff in the array because if I put the console log inside a partytown script I can see all its content. For example by doing this at the end of my body tag:

<script type="text/partytown">console.log(window.dataLayer)</script>

Does anyone know how to log this content directly in the console on demand? I tried running the console log in the web worker console, but that didn't work because window is not defined in the web worker.

0

There are 0 best solutions below