Analytics Content Grouping Using WordPress Categories and Not using Googles Tag Manager

Analytics Content Grouping can be very useful to see how a range of products is doing in the market in a quick and intuitive way and also allows for some interesting insights that are hard to get to in any other ways.

In the past I have relied on manual tagging of pages, but over time as new pages are added, this manual tagging drifts and the ‘not set’ category increases. As a way to automatically group pages a great way would be to use WordPress categories and group based on category names.

Before I go any further I should add that most of the pages I want to group are product pages and all of them are in multiple categories. For example a product might be in a categories for products, industrial, steel and more. This method is based on picking out a few of those categories only as groups. In this case Industrial is the group I want to add this to. If you have pages with 1 category only, there are other methods that are even more automated (see below).

I should add that this method is loosely based on the article of https://www.highposition.com/blog/how-to-send-author-content-groups-wordpress-google-analytics/ and I will follow the same steps that they take you through: –

Step 1 – Configuring Content Groups

Log into your analytics account and click on the Admin link in the top menu bar. Select the account and property you want and in the View section on the left, you should see Content Grouping: –

analytics-content-groups-setup1

We then need to create a new Content Group

Click the “Create New Content Grouping” button at the top.

Add in the title of your Group, in our case “Categories”.. but you can call it anything you wish.

Just below the title is where you select the tracking method you wish to use, we will be tracking via the GA javascript code, so click the first option, “Group By Tracking Code”, you don’t need to change anything on this screen, just press “Done” at the bottom.

Now do the same process again for any others you want to add to a maximum of 5, but when clicking the tracking code implementation option, make sure you change the “Index Number” option, so they are unique.

Step 2 – Modifying the Analytics Tracking Code

This article assumes that you are using the universal analytics code that Google has been pushing for some time. The code you have running on your site should therefore look something like this: –

<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’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-XXXXXX-X’, ‘auto’);
ga(‘send’, ‘pageview’);

</script>

We want to change it to add an extra line as shown below (in this case to add the category name, which is industrial to contentGroup4, which is the one I set up in the step above: –

<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’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-XXXXXX-X’, ‘auto’);
ga(‘set’, ‘contentGroup4’, ‘Industrial’);
ga(‘send’, ‘pageview’);

</script>

Find this code in your site. In theory it should be in the head section, but I load mine in the footer just in case Google is slow (which is quite often). You will often find this code in either the theme settings, a wordpress plugin or in the footer.php or header.php of the theme you are using. The code should look exactly as the top example above, so, after backing up, make a space between the ga(‘create’, ‘UA-XXXXXX-X’, ‘auto’); and ga(‘send’, ‘pageview’); lines to type in your new code to add the content groups.

The code I am using assumes that you know the groups you want to track, you have a page in multiple categories (see below if you have 1 category) and you don’t have many groups (as each one needs a line of code).

<?php
if(in_category(’19’)){echo “ga(‘set’, ‘contentGroup4’, ‘Industrial’);\n”;}
elseif(in_category(’16’)){echo “ga(‘set’, ‘contentGroup4’, ‘Industrial2’);\n”;}
elseif(in_category(’18’)){echo “ga(‘set’, ‘contentGroup4’, ‘Industrial3’);\n”;}
elseif(in_category(’11’)){echo “ga(‘set’, ‘contentGroup4’, ‘Industrial4’);\n”;}
?>

So this is very simple, each line checks to see if the page is in a particular category and if it is adds the analytics code to tag to page. In more detail:

if(in_category(‘19‘)) – Checks to see if the page is in category 19. You can get the category number easily by going to the category page in WordPress (under Posts), finding the particular category you want, then hovering your mouse over the top. In most browsers you will see the url of the link you would go to if you clicked. In that url you will see “tag_ID=19” in this case, but the number is the number you need to enter here.

{echo “ga(‘set’, ‘contentGroup4’, ‘Industrial’);\n”;} – This bit is just the code from analytics, but I have manually written in the category name. In this case Industrial. You could do this in code, but if I am setting the category ID for an individual line, you might as well just add it in manually. \n gives you the line break.

If you add that in to your analytics code it should look like the below: –

<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’,’//www.google-analytics.com/analytics.js’,’ga’);

ga(‘create’, ‘UA-XXXXXX-X’, ‘auto’);
<?php
if(in_category(’19’)){echo “ga(‘set’, ‘contentGroup4’, ‘Industrial’);\n”;}
elseif(in_category(’16’)){echo “ga(‘set’, ‘contentGroup4’, ‘Industrial2’);\n”;}
elseif(in_category(’18’)){echo “ga(‘set’, ‘contentGroup4’, ‘Industrial3’);\n”;}
elseif(in_category(’11’)){echo “ga(‘set’, ‘contentGroup4’, ‘Industrial4’);\n”;}
?>
ga(‘send’, ‘pageview’);

</script>

Once you load up a page this should then be tagged appropriately with the categories you have set.

Step 3 – Viewing Your Data

Once this new data has begun flowing in to your GA account, head over to your All Pages Report….  Behaviour -> Site Content -> All Pages

analytics-content-groups-setup2You will see a new option appear at the top of the report asking which content group you would like to see your pages grouped by. You should now see your groups in there. Select the group you want and it will show you pages together with useful on-site behavioural metrics. This can be very useful to see how certain sections or product ranges are performing against site stats over time.

Another interesting way to display this information is in a Dashboard. I particularly like to use the map view on the dashboard so I can see how particular groups are performing in different parts of the country or the world: –

If you have Single Category for Each Page

If each of your pages only has a single category, and you have a much larger range of categories. You may want to use this code instead as it automatically fetches the 1st category the post is in. Note that this is for Universal Analytics and also creates a group for the first tag. If you don’t want the tag group, just delete that section: –

<?php if (is_single()){
while(have_posts() ) : the_post();

$category = get_the_category();
if ($category && !empty($category[0]->cat_name)){
echo “ga(‘set’, ‘contentGroup4’, ‘”.$category[0]->cat_name.”‘);\n”;
}

$tag = get_the_tag();
if ($tag && !empty($tag[0]->tag_name)){
echo “ga(‘set’, ‘contentGroup5’, ‘”.$tag[0]->tag_name.”‘);\n”;
}

endwhile; // end of the loop.
}
?>

Explanation

<?php if (is_single()){
while(have_posts() ) : the_post();

………..

endwhile; // end of the loop.
}
?>

This section just makes sure that the page includes a single post only.

$category = get_the_category();

This section creates a group (array) of categories.

if ($category && !empty($category[0]->cat_name)){

This makes sure there is a category assigned and if there is applies the category name rather than the ID number or slug.

echo “ga(‘set’, ‘contentGroup4’, ‘”.$category[0]->cat_name.”‘);\n”;

This is the section that actually writes the line into the page html (echo). In this case the start of that is all just text from Google analytics. Change contentGroup5 to whatever content group you have set in the Analytics admin panel. The options are basically contentGroup1 to contentGroup5. The next bit ‘”.$category[0]->cat_name.”‘ is really the crucial bit that pulls in the category name. This will be the first category on the list you see in the pages, All pages list in WordPress.

IE8 InPrivate Filtering, A Google Killer?

In the final release of Internet Explorer 8 (IE8) there is a feature called InPrivate Filtering. What this does is as follows: –

Today websites increasingly pull content in from multiple sources, providing tremendous value to consumer and sites alike. Users are often not aware that some content, images, ads and analytics are being provided from third party websites or that these websites have the ability to potentially track their behavior across multiple websites. InPrivate Filtering provides users an added level of control and choice about the information that third party websites can potentially use to track browsing activity.

Although this would seem like a good idea, and to be fair has to be enabled on a per session basis, is this a thinly disguised  dig at Google Analytics?

Most sites these days tend to use Googles Analytics stats package which puts a cookie in the browser to allow the package to track repeat visitors etc.

Although Google don’t specifically say much about what they get out of Analytics the last code update made it fairly clear that site owners could track across domains, so it seems likely that Google are too.

Obviously this information is valuable to Google for advertising purposes, but it also ensures that potentially all of us are being characterised probably without any identifiying information, but characterised all the same.

InPrivate filtering seems to be Microsofts approach to reducing the amount of data Google can collect. By blocking Analytics cookies you are essentially also blocking Googles, and the individuals websites ability to track you. A smart move on Microsofts part.

As mentioned earlier this has to be enabled on a per session basis, so is it a shot across Googles bows saying that if your not careful, we’ll block 65% of the information you receive?

What is my feeling on this? As a site owner, I would hate analytics, or any other stats package to break. This helps me improve my site for others and is an invaluable tool. However I am concerned that information on my browsing habits could be being collected on me to serve me ads., or for some other purpose I would hate to consider.

On the other hand I don’t see MS as a fighter for our rights either. Seems to me that this is just good business for Microsoft, and if they can make it seem like they are doing good at the same time….

Google Launch Adwords Guide for SME

Google have just launched a guide to setting up Adwords designed specifically for small business in Australia.

I haven’t been though it yet but will edit this post as soon as I have to give my opinion. It’s good to see them demistifying, I just hope they have explained it with sufficient clarity.

http://www.10searchmarketingsteps.com.au/

Why Yahoo was right to hold out (and Google has it wrong)

In the last few weeks there has been many articles about Yahoo, that they are unfocused, and should have sold to Microsoft, but in one area they are the leaders and are killing Google. Don’t get me wrong here, I love Googles stuff in general but on the mobile phone, they suck!

First let me explain why this is a big deal. There is a growing tendency for people to access the web via their mobile and all the big players in the search market want a slice of the action. Why is this of interest to them? Simply because of the numbers involved. There are about 850 million PC’s out there at the moment where search engines can make their money, but 2.7 billion mobile phones. That is more than 3 times the number of phones than PC’s.

Think about it in terms of market share, at the moment Google has 60% of the PC market say, but if you add mobiles into the mix, that would be just a 14% share of the total available market. If someone moves into that mobile space, Google could be sidelined!

Okay, so having said that, where are they going to make their money? Ads are the obvious answer, and to a large extent an ad served to a mobile is even more compelling than those served on a PC search. The advantage of mobile is that they know where you are, so can send you ads that may not relate to the search, but more to your location? Maybe you can resist that coffee now, but could you if you were given 20% discount from the place you are just passing?

So what do Yahoo do so write that Google do wrong? They look at intent rather than just content.

If you do a search on Google mobile, you will be returned almost exactly the same results as you will be on their desktop browser. If you look at Yahoo though you get their top 3 normal web links, and their top 3 mobile web links. You can chose to navigate to more normal or more mobile links from there.

At this point you can see there is a fundamental difference between the two approaches. My guess is that Google is expecting that you would use an iPhone or similar which has full browsing capabilities, however this is missing the point. If you are out on the road somewhere, navigating with one hand you need content and design to suit that requirement.

As an example I live in Brisbane Australia and often travel into the city by train. If I search on Google for Brisbane Train Times using my Sony K800i, or my iPod Touch I get a list of full websites that often to be honest don’t give me what I want, train times quickly and in a form factor convenient form. However go to Yahoo and do the same and you get the local council version, and a mobile specific train times program, which gives me just what I want. This shows that Yahoo is looking at the intent of mobile browsing, and is inherently more usable.

On the iPod Touch I can obviously navigate full website with not too much effort, but the different is still astonishing. Try looking at http://www.qr.com.au and http://www.tad.tw and you can see for yourself.

The end result is that on my mobile I use Yahoo, and on my Mac I use Google. If this were to replicate through the mobile space with the positions of Yahoo and Google reversed on the different platforms, where would things sit? Google would end up with 29.6% of the market, and Yahoo with 50.4%*. Even if only half of the people used the mobile web Yahoo would still overtake Google in the total search market.

In short, Yahoo was right to hold off on Microsoft. If they can maintain their focus on the mobile market, in 2 or 3 years we could all be buying their stock.

* Figures are based on 60% of the 850 million PC using Google, and 20% using Yahoo. One the mobile 60% using Yahoo and 20% using Google.

Google Analytics New Code

I am just about to implement the new Google Analytics tracking code. One of the features of this is said to be cross domain tracking. This would be useful for us as I run more than 1 website with links between them, but are Google doing a doubleclick on this?

When I say that what I mean is that Doubleclick is notorious for putting a cookie on your system, then tracking you across the many sites they serve ads to. This invades the users privacy but allows them to build up a profile of who you are and what you like.

As Google has just acquired Doubleclick, are they trying the same trick? Wouldn’t allowing it’s users to track across domains, also allow Google to do the same across the many sites where analytics is installed.

I have to say I am a big fan of Analytics and am contantly amazed by the complexity and new features that are brought online, and for free. I am going to continue with the upgrade, but I am a bit worried about it!