META tags to dataLayer variables
This script will loop through HTML meta tags and, using some logic, turn them into GTM dataLayer variables.
by justincutroni
JavaScript
var metas = document.getElementsByTagName('meta');
for (i=0; i<metas.length; i++) {
if (metas[i].getAttribute('property') == 'article:published_time') {
var y = metas[i].getAttribute('content').split("-");
dataLayer.push({postYear : y[0]});
dataLayer.push({postMonth : y[1]});
}
if (metas[i].getAttribute('name') == 'twitter:creator') {
dataLayer.push({postAuthor : 'Justin Cutroni'});
}
}