2

I'm trying to use a JS function to retrieve data from categories, posts and etc, but I can't get any data.

Here is the code I've been trying to use:

gtm_datalayers = function() {
var dataLayer = window.dataLayer || [];
var dl_title = document.getElementsByTagName('title')[0].innerHTML;
var metaPub = document.querySelector("meta[property='article:published_time']");

if(metaPub){
    var dl_date = document.querySelector("meta[property='article:published_time']").getAttribute("content");
} else {
    var dl_date = document.getElementsByClassName('published')[0].innerHTML;
}

var dl_author = document.querySelector("meta[name='author']").getAttribute("content");
var dl_category = document.querySelector("meta[property='article:section']").getAttribute("content");
//var dl_dates = dl_date != '' ? dl_dateEntry : dl_date;

dataLayer.push({
    'Date': dl_date,
    'Author': dl_author,
    'Post': dl_title,
    'Categories': dl_category,
});

console.log(dl_date, '\n', dl_author, '\n', dl_category, '\n', dl_title);

}

I placed correctly my custom dimensions in GTM , Analytics, but it seems that something is missing.

UPDATE

Here my configuration of my Custom Report:

enter image description here

Here is my Custom Dimension Config

enter image description here

  • Care to share the url? – Kristian Svensson Sep 13 '17 at 23:10
  • @KristianSvensson sure devstate.de – Locke Sep 14 '17 at 0:12
  • I just had a quick look but I can't see your code anywhere. Is it published anywhere on devstate.de ? – Kristian Svensson Sep 14 '17 at 6:52
  • @KristianSvensson the dataLayer only triggers in single post with GTM :D – Locke Sep 14 '17 at 15:34
  • I don't see the meta tag for author in your single post mark-up. There is an anchor tag which contains the rel=author which you can use to pick-up the correct string though. – Prasad Ajinkya Sep 20 '17 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.