Вопрос

Seems like this would be quite simple but i cannot find much documentation available. Currently on our article system, each author name appears like this on each page:

<div id="author-info">
    <a href="/articles/mr-man" rel="author">Mr. Man</a>

According to Google, using custom dimensions is the way to do track authors in UA. Setup a custom dimension "Author" and set the scope to Hit/Session/User. Not sure i fully understand the different scope options. I get the following code:

var dimensionValue = 'SOME_DIMENSION_VALUE';
ga('set', 'dimension1', dimensionValue);

Which i'm assuming should be:

var author-id = 'Mr. Man';
ga('set', 'dimension1', author-id);

Is that correct? Also, how can i pass the author information into the dataLayer and then call the author page views through GTM? How about multiple authors?

Это было полезно?

Решение

Ok, this answer comes from the G+ analytics community (link below). Credit goes to https://plus.google.com/u/0/+SimoAhava

Using GTM, we can do the whole thing using macros and set fields:

Create a Custom JavaScript Macro which returns the author name:

function() {
  try{    
    return document.getElementById("author-info").children[0].text;
  } catch(e) {
    return "";
  }
}

In your Pageview tag, go to More Settings -> Custom Dimensions, add custom dimension, put the index number of the CD you created in the required field and add the JavaScript macro to the Dimension field.

This setup grabs the text content of the page's author link and sends it as a custom dimension with the pageview. Since it's hit-scope, every pageview will be attached with the author info of the page.

https://plus.google.com/104258622890980927916/posts/e6cC6y8q1m6

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top