3

Assuming GTM is loaded and initialised, I want to use window.dataLayer.push() in ReactJS using the following code as soon as the page is loaded:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push( { 'myvalue': value} );
console.log('window.dataLayer', window.dataLayer);

I've tried adding to componentDidMount() and before the return-statement in render() to no avail. The values are not pushed to the dataLayer from either of those locations.

Could anyone please advise where I should place the code to achieve the result of pushing the values to the dataLayer upon page load.

quinny
  • 656
  • 1
  • 7
  • 24

0 Answers0