Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should variables be quoted in GTM custom html tag?

I am trying to implement facebook pixel via GTM, and I am hitting a few oddities.

I am implementing via custom html tag, and If i dont quote the variables, the gtm debugger shows them as google_tag_manager["<ID>"].macro(\'gtm123123123\')in the debugger, instead of the value itself. If i surround the use of the variable with quotes, I see the value itself.

If the {{User Email}} is translated into javascript code as i am seeing, I presume quoting isnt required?

If I need to quote, how would I write code like? em: ({{User Email}} || "").toLowerCase(),

Which is recommended? How to decide?

Also the debugger surrounds the entire tag in a '' is this expected?

like image 435
Karthik T Avatar asked Oct 18 '22 05:10

Karthik T


1 Answers

In Custom HTML Tags you reference your Variables with the double brackets as per your example, without the quotes. e.g.

var userEmail = {{User Email}};

The Preview Mode Debug Panel is showing a non-executed version of your Custom HTML Tag. So the '' wrapped around your script in the panel output is expected. This is also why your Variables are not showing as values, instead you are seeing the internal GTM reference to your Variable.

If you need to test your Variable you can temporarily include a console.log(); To ensure your values is resolving correctly. e.g.

var userEmail = {{User Email}};
console.log(userEmail);
like image 70
Max Avatar answered Nov 15 '22 05:11

Max