2

I'm trying to track visits to specific topics on my website. Each article can be tagged with several topics so it seems the only way to track visits per topic is by firing an event for each topic the article is in.

I am using Google Analytics (UA) and Google Tag Manager.

So far I have created the following as a Custom HTML Tag in GTM:

<script>
var wt_topics = $("meta[name='WT.cg_n']").attr("content");
var topic_array = wt_topics.split(';');
var uniqueTopics = [];
$.each(topic_array, function(i, el){
    if($.inArray(el, uniqueTopics) === -1) uniqueTopics.push(el);
});

var recordTitle = $("meta[name='DCSext.recordtitle']").attr("content");

$.each(uniqueTopics, function( index, value ) {
  ga('send', 'event', 'Topics', value, recordTitle);
});
</script>

This converts a string available on the webpage into a JavaScript array of topics, then it removes any duplicates, and finally fires an event for each item in the array. Or at least, it is supposed to do that last bit.

If I replace the ga('send'... code with an alert() tag it works, so I suspect it doesn't know what the term 'ga' is supposed to.

What am I doing wrong? and is there a better way to do this, using GTMs macros, tags, etc?

Thanks

1 Answer 1

1

Have you taken a look at Content Groupings? Plus, Google just released the ability to add Content Groups via Google Tag Manager.

Content Grouping lets you group content into a logical structure that reflects how you think about your site or app, and then view and compare aggregated metrics by group name in addition to being able to drill down to the individual URL, page title, or screen name. For example, you can see the aggregated number of pageviews for all pages in a group like Men/Shirts, and then drill in to see each URL or page title.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I looked into that but you can't have multiple groups per page, which is what I need. It's really strange because it sounds like it would be an often-requested feature (eg blog tags, news topics, product categories, etc) but unless I'm searching for the wrong stuff no one has a solution.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.