Every once and a while there are reasons where you may have some site owners who want individual reports for themselves and then some other entity wants to measure each site against the others. This can often be the scenario in the case of a franchise.
Let’s say we have our BigCompany corporate headquarters with BigCompany franchises located across the country. Well, the BigCompany franchise in Grand Rapids, MI wants its own Analytics profile so it can measure visits, bounce rates, conversion rates, etc. without having to sift through the data from the Portland, OR location. Likewise, the Portland franchise wants to measure its site performance independent from the Grand Rapids location. However, BigCompany headquarters wants a report that shows the performance of ALL franchise locations across the country. This is a great opportunity to create a Google Analytics roll up report through a little Google Analytics hack!
This hack basically would allow someone to roll up the reports from many profiles into one profile. The hack is quite simple once you see it – and then you think, “why the heck didn’t I think of that!?” It’s pretty straight forward and would just require a small change to the Google Analytics Tracking Code (GATC) on each franchise site.
Existing GATC on Franchise Site
Let’s say the GATC on each franchise site looks like this. This is a direct copy from the Google Analytics site:
<span style="color: #606060" id="lnum1"> 1:</span> <script type=<span style="color: #006080">"text/javascript"</span>>
<span style="color: #606060" id="lnum2"> 2:</span>
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">var</span> _gaq = _gaq || [];
<span style="color: #606060" id="lnum4"> 4:</span> _gaq.push([<span style="color: #006080">'_setAccount'</span>, <span style="color: #006080">'UA-1234567-1'</span>]);
<span style="color: #606060" id="lnum6"> 6:</span>
<span style="color: #606060" id="lnum7"> 7:</span> (<span style="color: #0000ff">function</span>() {
<span style="color: #606060" id="lnum8"> 8:</span> <span style="color: #0000ff">var</span> ga = document.createElement(<span style="color: #006080">'script'</span>); ga.type = <span style="color: #006080">'text/javascript'</span>; ga.async = <span style="color: #0000ff">true</span>;
<span style="color: #606060" id="lnum9"> 9:</span> ga.src = (<span style="color: #006080">'https:'</span> == document.location.protocol ? <span style="color: #006080">'https://ssl'</span> : <span style="color: #006080">'http://www'</span>) + <span style="color: #006080">'.google-analytics.com/ga.js'</span>;
<span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #0000ff">var</span> s = document.getElementsByTagName(<span style="color: #006080">'script'</span>)[0]; s.parentNode.insertBefore(ga, s);
<span style="color: #606060" id="lnum11"> 11:</span> })();
<span style="color: #606060" id="lnum12"> 12:</span>
<span style="color: #606060" id="lnum13"> 13:</span> </script>
<span style="font-family: arial">So, with a little change-a-roo, we just add a reference to the other Google Analytics profile. The code would then look like this:</span>
<span style="font-family: arial"> </span>
<span style="color: #606060" id="lnum1"> 1:</span> <script type=<span style="color: #006080">"text/javascript"</span>>
<span style="color: #606060" id="lnum2"> 2:</span>
<span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">var</span> _gaq = _gaq || [];
<span style="color: #606060" id="lnum4"> 4:</span> _gaq.push(
<span style="color: #606060" id="lnum5"> 5:</span> [<span style="color: #006080">'_setAccount'</span>, <span style="color: #006080">'UA-1234567-1'</span>],
<span style="color: #606060" id="lnum6"> 6:</span> [<span style="color: #006080">'_trackPageview'</span>],
<span style="color: #606060" id="lnum7"> 7:</span> [<span style="color: #006080">'hq._setAccount'</span>, <span style="color: #006080">'UA-1234567-2'</span>],
<span style="color: #606060" id="lnum8"> 8:</span> [<span style="color: #006080">'hq._trackPageview'</span>]
<span style="color: #606060" id="lnum9"> 9:</span> );
<span style="color: #606060" id="lnum10"> 10:</span>
<span style="color: #606060" id="lnum11"> 11:</span> (<span style="color: #0000ff">function</span>() {
<span style="color: #606060" id="lnum12"> 12:</span> <span style="color: #0000ff">var</span> ga = document.createElement(<span style="color: #006080">'script'</span>); ga.type = <span style="color: #006080">'text/javascript'</span>; ga.async = <span style="color: #0000ff">true</span>;
<span style="color: #606060" id="lnum13"> 13:</span> ga.src = (<span style="color: #006080">'https:'</span> == document.location.protocol ? <span style="color: #006080">'https://ssl'</span> : <span style="color: #006080">'http://www'</span>) + <span style="color: #006080">'.google-analytics.com/ga.js'</span>;
<span style="color: #606060" id="lnum14"> 14:</span> <span style="color: #0000ff">var</span> s = document.getElementsByTagName(<span style="color: #006080">'script'</span>)[0]; s.parentNode.insertBefore(ga, s);
<span style="color: #606060" id="lnum15"> 15:</span> })();
<span style="color: #606060" id="lnum16"> 16:</span>
<span style="color: #606060" id="lnum17"> 17:</span> </script>
See the changes on lines 3 through 8? All we did is add the profile ID (UA-1234567-2) from the BigCompany headquarters location to our GATC. Notice we also had to append an ID to the beginning of the _setAccount and _trackPageview calls. In this example, I just used “hq” but it could be anything you wanted. It does need to end in a period though, as that’s the JavaScript object notation syntax.
There, see how easy that was? Now when the GATC executes, it will track the page view to the local franchisee profile, as well as the HQ “roll up” profile!
Some Gotchas
Page Names
If page names are the same across all the sites you’ll be tracking in your roll up report, you’ll want to set up a filter in the roll up report to append the domain name and URI. There are a lot of places you can check on how to do that but, for the sake of convenience, I’ve included here from the Google Code site:
Modify your cross-domain profile with a filter to show the full domain in your content reports.
Once you have domain linking established, you will see only the request URI in the content reports, and not the top-level or sub-domain for a given page. So for example, for visits to the following pages:
—
http://www.example.com/index.php
and another page on—
http://sub.example.com/more.php
The reports will show:
— index.php
— more.php
You will not be able to distinguish which page is from which domain. To show the domain in the page reports, set a filter to include all components of the page URL, as follows:
- In the Profile Settings page, click the Add Filter link.
- Choose Add New Filter and provide the filter a name.
- Choose Custom Filter and select Advanced on the Filter type settings.
- Under Advanced settings:
- FieldA should be set to Hostname
- FieldB should be set to Request URI
- Set the values for both Field A and Field B to
(.*)
, which is an expression that captures all characters.- Set the Output To –> Constructor option to Request URI and provide
$A1$B1
as the value for that choice.Your reports will now show:
—
www.example.com/index.php
—
sub.example.com/more.php
This will capture the
www.example.com
portion of your URL and include that at the beginning of your page URL in the content reports section.
Tracking Across Sites
If you have the situation where you want to track a visitor from BigCompany.com to BigCompanyFranchise.com this is possible – just not with this method. Let’s save that for another post!
Clear as a Bell Summary
The ability to offer roll up reporting is very convenient in some situations. It’s definitely possible with a small GATC hack to push the traffic to two profiles at once!