Search
Clear search
Close search
Google apps
Main menu

New Custom HTML and Custom JavaScript Macro Behavior

All macros used in Custom HTML tags and Custom JavaScript macros will now return the same value for the duration of an event. If you currently have code that depends on changing the value of a macro during an event, move that logic into a Custom HTML tag - when you're finished processing and ready to use the final value, push an event to the data layer that indicates the macro is ready to use.

For example, if you have a custom HTML tag that uses a macro called {{productKey}} based on a JavaScript variable productKey:

Custom HTML Tag #1

function() {
  productKey = productKey.toUpperCase();
  // use {{productKey}}
}

This now won't work because {{productKey}} won't return the new value for the next event. You can get the same behavior by pushing a new event that fires a new tag:

Custom HTML Tag #1 fixed

function() {
  productKey = productKey.toUpperCase();
  dataLayer.push({'event' : 'productKeyReady'});
}

Custom HTML Tag #2, fired on event productKeyReady

function() {
  // use {{productKey}}
}
Was this article helpful?
How can we improve it?