Reputation: 1
We have a website on which multiple cards get rendered on a page, some cards are article,video,poll quiz cards etc. The cards can be shared, like
We want to create a DTM datalayer for this, so that we can do effective implementation using DTM
Any help on this for sample datalayer, resource links will be appreciated
Upvotes: 0
Views: 570
Reputation: 344
DTM can use both a data layer as well as HTML on the page. Depending on what you are trying to do, you can put the different attributes in an HTML element, and use some code in DTM to scrape that data from the page and do what you need to do with it.
For example, let's say that each card you have has a class of "card". And you need to know the card type and card ID. Here is something you can do:
<div class="card" data-cardType="article" data-cardID="1">...</div>
<div class="card" data-cardType="video" data-cardID="2">...</div>
<div class="card" data-cardType="poll" data-cardID="3">...</div>
You can then use JavaScript/jQuery to loop through the cards and get what you need. For example, let's say you were populating the card type and card ID in the Adobe Analytics products variable:
var prods = [];
$('.card').each(function(){
prods.push(';'+$(this).attr('data-cardID')+';;;;evar1='+$(this).attr('data-cardType'));
});
s.products = prods.join(',');
The other option would to actually build the same data structure in JavaScript, and use some code to loop through it and get the data you need.
Upvotes: 1