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

analyticsacdm
Visitor
1 0 0

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" %}
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'login',
'customerType': 'regular',
'registrationCountry': 'France'
});
</script>

{% endif %}

 

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

 

Capture d’écran 2022-05-02 à 21.29.56.pngCapture d’écran 2022-05-02 à 21.30.21.png

 

Could you help me please?

 

Thanks

Reply 1 (1)

Michel_Arteta
Shopify Partner
33 2 34
  • 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.