Treasure Data works with Google Tag Manager to (GTM) to collect your data into a single place. Together, this integration makes Google’s management tool more powerful for your needs.
Table of Contents |
---|
Prerequisites
Basic knowledge of JavaScript / HTML
Basic knowledge of Treasure Data
Creating the Tag
After you have created your container, you can create a new tag within it as a Custom HTML Tag.
Open Google Tag Manager.
Select your container.
Add the following lines into the Configure Tag section, with your write-only API key and database name. The following tag should be associated and fired by All Pages trigger.
Code Block linenumbers true <!-- Treasure Data --> <script type="text/javascript"> !function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},s=["addRecord","blockEvents","fetchServerCookie","fetchGlobalID","fetchUserSegments","resetUUID","ready","setSignedMode","setAnonymousMode","set","trackEvent","trackPageview","trackClicks","unblockEvents"],n=0;n<s.length;n++){var c=s[n];e[t].prototype[c]=r(c)}var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/2.5/td.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(o,a)}}("Treasure",this); // Configure an instance for your database var td = new Treasure({ host: 'in.treasuredata.com', writeKey: 'YOUR_WRITE_ONLY_APIKEY_IS_HERE', database: 'DATABASE_NAME' }); // Enable cross-domain tracking td.set('$global', 'td_global_id', 'td_global_id'); // track pageview information to 'pageviews' table td.trackPageview('pageviews'); </script>
Your screen might look like this.
Tracking the Click URL Variable
You can track links users click by setting the Click Trigger, which sends an additional JavaScript tag with your data and the {{Click URL}} variable to Treasure Data. The {{Click URL}} variable contains the URL information of the link. You can use the Click Trigger to track when users have clicked links to external sites on which you cannot track page-view.
Enabling the {{Click URL}} Variable
From your workspace, select Variables.
Select Configure.
In the Clicks section of the variables panel, select Click URL.
Defining the Click Trigger
From your workspace, select Triggers.
Select New.
In the Trigger Configuration Panel, select Click - Just Links. The Clicks tag is selected under References to this Trigger, so that any references to the trigger fire.
Setting the Tag for the Click Trigger
In the References to this Trigger panel, select Clicks.
Select Custom HTML under Tag Type.
In the HTML section, insert the following code.
Code Block linenumbers true <script type="text/javascript"> !function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},s=["addRecord","blockEvents","fetchServerCookie","fetchGlobalID","fetchUserSegments","resetUUID","ready","setSignedMode","setAnonymousMode","set","trackEvent","trackPageview","trackClicks","unblockEvents"],n=0;n<s.length;n++){var c=s[n];e[t].prototype[c]=r(c)}var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/2.4/td.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(o,a)}}("Treasure",this); // Configure an instance for your database var td = new Treasure({ host: 'in.treasuredata.com', writeKey: 'YOUR_WRITE_ONLY_APIKEY_IS_HERE', database: 'DATABASE_NAME' }); // Enable cross-domain tracking td.set('$global', 'td_global_id', 'td_global_id'); // Track click information to 'clickviews' table var click_url = {{Click URL}}; td.set('clickviews', {click_url: click_url}); td.trackPageview('clickviews'); </script>
...
You might have two TD tags registered for All Pages and click_trigger.
Excluding Data from Google Tag Manager
You might see records associated with Google Tag Manager. See the following table for examples of the data contained in these records.
...