skip to Main Content

I need to insert a code that contain double curly braces (Its a Shopify liquid object)

That code i need to insert looks like this { collection.products_count }}, The purpose of that code is that when you insert it on specific object it return something depend on the code used so it can return the product price.. order discount etc..

Now the problem is that Google Tag manger uses the same double curly braces format for its variables so if insert that above shopify code into it hopefully GTM plant it into the store page it just return an error that this variable is not exist because GTM think its a GTM variable and cant recognise it as a Shopify Liquid Object.

Is there any solution or workaround for that issue?

Thanks

2

Answers


  1. You need to understand the way the Shopify platform works. When you create any Liquid tags and add them to your theme, Shopify renders those first. That means when your theme has code like {{ collection.products_count }} Shopify evaluates that and turns it into a number. That number is then available for your use. What that means is that you are not actually sending curly braces to Google. Google only gets a call and can accept data AFTER your Liquid is rendered, not before. So you simply need to structure your data for Google in the Google fashion, not with respect to Liquid.

    Login or Signup to reply.
  2. This is an old post but came across it as I had to use double curly braces for a third-party project and had the same issue of GTM not accepting custom JS code containing double braces. I got around this by concatenating strings and will provide my solution here in the hope of helping others.

    Instead of the following that was not accepted by GTM:

    message: {
      consent: 'I accept the {{ link:https://example.com/privacy privacy policy }}'
    }
    

    I used the following code:

    message: {
      consent: 'I accept the {' + '{ link:https://example.com/privacy privacy policy }' + '}'
    }
    

    This will only help if the double curly braces are in a string, but might help in some instances.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search