google-analytics

How to group articles by meta article:tags in Google Analytics?


I'm managing a web blog and each article has tags. I was wondering if I could see these tags in Google Analytics to see which tags are the most viewed.

The tags are present in the page, in the form of meta property, with multiple tags per page, for instance:

<meta property="article:tag" content="C++">
<meta property="article:tag" content="Performances">

Is there any way to get this information in Google Analytics ?

Most of my pages have several tags. I would need analytics on each tag individually, not on combinations of tags.

Edit: Here is what I tried:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-XXXXXXX-X', 'auto');
  var metas = document.getElementsByTagName('meta'), tagsList = [];
  for (var i=0; i<metas.length; i++) {
    if (metas[i].getAttribute('property') == 'article:tag') {
      tagsList.push( metas[i].getAttribute('content'));
    }
  }
  ga('set', 'dimension1', tagsList.join('|'));
  ga('send', 'pageview');
</script>

It's working if the script is AFTER the meta properties.


Solution

  • You may send the list of tags as a google analytics custom dimension.

    This will let you see the tags associated to each page in the Google Analytics reports, together with the traffic metrics.

    The drawback is that in the reporting, for a page having multiple tags, you will get the number of visits for this combination of tags, rather than the number of visits for each individual tag. You will need to download the report data in a spreadsheet, or perhaps in Google Data Studio, to cleanup and get the figures by tag.

    How to implement

    1. define the dimension in Google Analytics

    The custom dimension should be set with at "hit level scope", this means that their values will be linked to the visited page(s).

    Follow the setup instructions.

    2. Send the tags list at page load

    You should use javascript to lookup the meta tags, and send them to Google Analytics:

    // read the set of tag values in javascript
    // based on https://stackoverflow.com/a/7524621
    var metas = document.getElementsByTagName('meta')
        , tagsList = []
    
    for (var i=0; i<metas.length; i++) {
      if (metas[i].getAttribute('property') == 'article:tag') {
         tagsList.push( metas[i].getAttribute('content'))
      }
    }
    
    // set the list of tags as dimension value - as a comma-separated string
    ga('set', 'dimension1', tagsList.join(','))
    
    // then only send the pageview
    ga('send', 'pageview')
    

    3. Profit!

    In Google analytics reporting, the tags list can now be added to existing reports, or you may also create custom reports using them.

    For example, try to add the tags list as a secondary dimension in Behavior/Site Content / All Pages report. Then click on "save" button at the top-right of the screen to re-use easily later.

    The dimension will contain concatenated values of the tags, e.g. C++,performances rather than individual tags.

    You may use either advanced filters or segments in order to get the metrics values per tag, e.g. the following filter will show you the metrics for the pages containing this tag:

    dimension1 contains "C++"
    

    If you want to go further and see all tag metrics in one report, use the Export feature to use the data in Excel, where you'll be able to split the tags list into individual tags.