3

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

6
  • Care to share the url? Sep 13, 2017 at 23:10
  • @KristianSvensson sure devstate.de
    – Locke
    Sep 14, 2017 at 0:12
  • I just had a quick look but I can't see your code anywhere. Is it published anywhere on devstate.de ? Sep 14, 2017 at 6:52
  • @KristianSvensson the dataLayer only triggers in single post with GTM :D
    – Locke
    Sep 14, 2017 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. Sep 20, 2017 at 8:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.