How to add a dataLayer.push to a blog post?

Hello,

I’m trying to add this script to a blog post so that when a user lands on this page, these event values are pushed to the dataLayer.

Here is the script :

{% if page.url == “/blogs/news/login-page” %}

{% endif %}

However, nothing is apparent in the dataLayer. I put this script in theme.liquid.

Could you help me please?

Thanks

  • Try dataLayer = window.datalayer || and dataLayer.push instead of window.dataLayer
  • Move your GTM script to the top and this dataLayer push do it right after
  • Check if condition page.url works.