You are reviewing MouseStats documentation: Take a look to the product!
< back

Google Analytics integration using GTM

In this documentation, Google Analytics integration will be described when it is activated by Google Tag Manager (GTM).


How?

Step 1

First you need to create a Custom Dimension in Google Analytics. Create a Custom Dimension in Google Analytics. Make sure the Scope of dimension is "User". Choose a name like "MouseStats Visitor Id".



Step 2

In GTM, create a custom HTML tag that fires on All Pages:

<script type='text/javascript'>
var dataLayer = (typeof dataLayer == "undefined" ? [] : dataLayer)
window.onMouseStatsPlaybackStartRecording = function () {
 dataLayer = [{
    'MousestatsPlayback': MouseStatsVisitorPlaybacks.visitorId()
 }];
}
</script>

This script utilizes GTM dataLayer rather than the global ga() function.


Step 3

In GTM, click on "Variables" and choose "New" to create a new GTM variable:
  • Choose "Data Layer Variable" as type.
  • Enter "MousestatsPlayback" as Data Layer Variable Name.
  • Submit and create the variable with a custom name to be recognized by you (eg. MouseStats Playback Id Data Layer)



Step 4

Now, we have created our variable. Go back to your Google Analytics Universal Tag configuration in GTM.

  • Click on "Tags"
  • Choose your Google Analytics tag item
  • Go to Configure Tag > More Settings > Custom Dimensions > Add Custom Dimensions
  • 'Index' refers to Custom Dimension slot in Google Analytics, and `Dimension Value` should be: {{MousestatsPlayback}}