if you're trying to copy all data- attributes from all elements into the data layer you can run a jQuery snippet like this:
{code:javascript}
data_attr = {};
$("*").filter(function () {
var attrs = this.attributes;
for (var i = 0; i < attrs.length; i++) {
if (attrs[i].nodeName.indexOf('data') === 0) {
a = attrs[i].ownerElement;
b = attrs[i].ownerElement.parentElement;
key = b.localName + "-" + (!b.id ? (!b.className ? i : b.className) : b.id) + "_" +
a.localName + "-" + (!a.id ? (!a.className ? i : a.className) : a.id) + "_" +
attrs[i].nodeName.replace("data-", "");
window.data_attr[key] = attrs[i].nodeValue;
return true;
}
};
return false;
})
$.extend(utag.data, data_attr);
{code}
This will create (hopefully) unique keys and the values of the data-attribute to an object and merge them with the utag.data UDO.
something like below:
{code:javascript}
Object {html-2_body-com-html5doctor_twttr-rendered: "true", p-tweet_iframe-twitter-widget-0_twttr-rendered: "true", pre-1_span-tag_colors: "test"}
{code}
the varibale names might be a bit long, but since the data- attribute most likely will be reused in multiple elements I used a combination of element type,id,class, and data attribute to create the keys.
Hope this helps.
... View more