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']");

    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;

    '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.


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? Commented Sep 13, 2017 at 23:10
  • @KristianSvensson sure devstate.de
    – Locke
    Commented 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 ? Commented Sep 14, 2017 at 6:52
  • @KristianSvensson the dataLayer only triggers in single post with GTM :D
    – Locke
    Commented 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. Commented Sep 20, 2017 at 8:30


Your Answer

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