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

Google Analytics integration using GTM

In this documentation, Google Analytics integration will be described when it is activated by Google Tag Manager (GTM). If you want to integrate without GTM and you are only using normal Google Analytics Tracking Script, you need to take a look to the other documentation.


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.push({
    '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 enter the variable name as "MousestatsPlayback" - it should be named as "MousestatsPlayback"



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}}