This guide explains what the hitIdTracker
plugin is and how to integrate it into your analytics.js
tracking implementation.
When using Google Analytics to store data about different types of user interactions on your site, from pageviews, to custom events, to ecommerce transactions, Google Analytics does not provide an unique identifier to distinguish one interaction from another, which is specially when exporting data from Google Analytics for analysis outside of it. This plugin solves this problem by automatically generating and assigning a tiny, secure, URL-friendly, unique string ID to every user interaction tracked on your site.
The hitIdTracker
plugin works by relying on the GaTaskManager plugin to add a function to the Google Analytics Tasks API's customTask
execution. This function sets a Custom Dimension (which you specify) with a an url-friendly 21-character uuid value generated with the Nano ID library.
You must require
the GaTaskManager plugin before requiring the hitIdTracker
plugin.
You must configure a Custom Dimension with Hit
scope and reserve it for the IDs which will be automatically generated by the hitIdTracker
plugin. I suggest you name this Custom Dimension "Hit ID".
To enable the hitIdTracker
plugin, run the require
command, specify the plugin name 'hitIdTracker'
, and pass in the Custom Dimension index on which you want the Hit IDs to be stored:
ga('require', 'hitIdTracker', {customDimensionIndex: <number>});
Note: Requiring the plugin without first requiring the GaTaskManager plugin will result in an error.
The hitIdTracker
plugin takes one required option, customDimensionIndex
which should be a number
equal to the index of the hit-scoped Custom Dimension configured to store the Hit IDs.
Note: There's no default value. Requiring the plugin without providing {customDimensionIndex: <number>}
when calling require
will result in an error.
The following table lists all methods for the hitIdTracker
plugin:
Method Name | Description |
---|---|
remove |
Removes the hitIdTracker plugin from the specified tracker and removes the Custom Dimension setting function from GaTaskManager plugin |
For details on how analytics.js
plugin methods work and how to invoke them, see calling plugin methods in the analytics.js
documentation.