Search code examples
google-analyticsgoogle-tag-managergoogle-analytics-4

How to assign Google Tag Manager Custom Variable to Google Analytics Custom Dimension


I am new to Google Tag Manager and Google Analytics. Having set up basic tags in GTM that are mapped to Google Analytics I want to get improved insights by using HTML meta tag data To that end I have created a custom GTM variable with the following JS:

  var metaNames = ["foo", "bar", "blah" ];
  var metas = document.getElementsByTagName('meta');
  var content = undefined;
  
  for (i = 0; i < metas.length; i++){
     if (metaNames.contains(metas[i].getAttribute("property"))){

          content = metas[i].getAttribute("content");
     }
  }
  return content;
}

Having read Google documentation and searched the web I cannot figure out how to map the GTM variable to a GA "Custom Definition" or "Custom Metric". The "User Property" / "Event Parameter" field in GA does not appear to correspond to the GTM variable.

I want GA to use the GTM variable to produce analytics based upon the page meta data properties identified above.

Any assistance would be gratefully received.

Thanks and regards, Andrew


Solution

  • I have figured this out, under GTM Tag configuration the GTM variables need to be mapped to GA4 "Fields to set" or "User Properties". The variable will then be sent as part of the event fired by GTM