Post by Dhaupin » Tue Oct 07, 2014 12:57 am

Here is the basic theory behind getting Google Analytics set up to see all stores, domains, apps, etc in 1 view based on 1 property. Generally this requires an APP server or other sorta utility url (or subdomain) to become the analytics router. In this case we will use analytics.yourdomain.com


Step 1) Using example analytics.yourdomain.com as the router, make subdomain and point its root folder to a new folder on your server called something like "analytics". Make an analytics property in GA called something like "All Apps" while you're at it, make sure its using universal analytics, note its UA number.


Step 2) Now, make an index.html (or php) file in the root folder for that subdomain (analytics). We need to put a custom GA script here listing all domains of apps/stores/etc you want to connect to your "All Apps" GA property. Replace the list of domains with your chosen whitelist of domains able to access the router. Then replace the UA-00000000-00 with your "All Apps" property UA. Check the analytics subdomain in GA to make sure its sending data

Code: Select all

<!-- @CUSTOM Google Analytics Master Script -->
<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-00000000-00', 'auto', {'allowLinker': true});
  ga('require', 'linker');
  ga('linker:autoLink', ['mydomain.com, otherdomain1.com, otherdomain2.com, otherdomain3.com, otherdomain4.com, otherdomain5.com, otherdomain6.com, otherdomain7.com'] );
  
  ga('send', 'pageview');

</script>

Step 3) Now we can make it happen at store or app level. The following script would REPLACE the default GA universal analytics script that you are probably using. Assuming you already have a GA property for your store/app, take note of its UA. In the following script replace UA-11111111-11 with this property UA. Then replace UA-00000000-00 with your "All Apps" UA. Finally replace analytics.mydomain.com with your analytics router url to that index containing the above script.

Code: Select all

<!-- @CUSTOM Google Analytics Site Specific and All Apps Script -->
<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-11111111-11', 'auto');
  ga('send', 'pageview');
  
  ga('create', 'UA-00000000-00', 'auto', {'name': 'appTracker', 'allowLinker': true});
  ga('appTracker.require', 'linker');
  ga('appTracker.linker:autoLink', ['analytics.mydomain.com'] );
  ga('appTracker.send', 'pageview');
</script>

Step 4) Check to see if its working via real time. In the "All Apps" view in Google Analytics, click the Real Time > Overview. If everything is authd and routing properly, you should see live peoples who are on your store/apps listed as a bunch of tail urls. If you are having trouble seeing the domain in real time, see the next step to make a filter.


Step 5) We should make a filter to expose domain names in realtime and other tables. First, go into the Admin for the "All Apps" view. There should be a button for "Filters". Click that, then "Add new filter", then "Advanced Filter". Fill in the fields like so:

Code: Select all

Filter Type: Custom filter > Advanced
Field A: Hostname
Extract A: (.*)
Field B: Request URI
Extract B: (.*)
Output To: Request URI
Constructor: $A1$B1
Here is the guide right from Google on how to make this filter: https://support.google.com/analytics/an ... 2243?hl=en


** Note on Conversion Tracking: This mod won't affect the ecommerce tracking attached to the individual properties. Without modding the ecommerce tracking extension however, it will not push conversion info to "All Apps". You need to add "appTracker" guts to any ecommerce trackers in order to push to "All Apps". Here is the extension spoken of:
http://www.opencart.com/index.php?route ... n_id=11242


Now you should have your own analytics router. This can be used for multiple other analytics engines/services too. Hope that clarifies how to do this! Have fun with overall stats :)

https://creadev.org | support@creadev.org - Opencart Extensions, Integrations, & Development. Made in the USA.


User avatar
Active Member

Posts

Joined
Tue May 13, 2014 3:45 am
Location - PA
Who is online

Users browsing this forum: No registered users and 5 guests