1

I have the following array in my datalayer :

'pageCategory': ['Category1','Category2','Category3']

I would like to pass each one of these category within google analytics with a custom dimension. Following some answers I found on a Google Forum I create the following HTML tag in my GTM :

<script>
  var categories = {{sub_Categories}};

  for (var i=0; i<categories.length; i++) {
    dataLayer.push({
      event: 'categoryProcessed',
      category: categories[i]
    });
  }
</script>

In Preview debug mode, I can see that the tag is firing an event for each category and pushing for each event the value of each category in a different datalayer.

Then I kind of stuck, I don't realy know what should I go next. Do I need to fire my GA analytics TAG for each event ?

1 Answer 1

2

Yes, you could create a Custom Event Trigger for categoryProcessed, and then fire your Event Tag once for every single dataLayer.push(). You'd need to create a Data Layer Variable for category, so that you can pull the value in dynamically.

However, sending an event with every single category name is overkill. I would recommend sending the categories as a comma-separated string in a single Event tag's custom dimension field. That way you'll only have a single event firing on the page, sending all the categories like:

category1,category2,category3

Yes, I admit it's a bit ugly to read in the GA reports, since you can't just isolate each category as its own row, but you can extract the data out of GA and process it in Google Sheets, for example.

If you DO want to send one Event per category, then follow what I suggested in the first paragraph. Just note that you'll be sending a LOT of events to GA. You might also want to set the Non-Interaction field to True, so that you don't mess with sessionization (e.g. Bounce Rate) when doing so.

1
  • Thanks Simo. Since I'm mostly working from my spreadsheet I guess the comma-separated string is the best solution. Commented Oct 7, 2016 at 16:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.