Try out all OWOX BI features with a trial period Start for free

OWOX BI tracking code integration with Google Tag Manager

To finish setting up a user behavior data pipeline from your website to Google BigQuery, you need to integrate the OWOX BI tracking code on your website.

If you're using Google Tag Manager to send website event data to Google Analytics, you can also use it to integrate the OWOX BI tracking code.

How to set up website data collection to Google BigQuery tracking with Google Tag Manager

Step 1

1. In a Google Tag Manager container, create a Custom JavaScript-type customTask variable. To do it, go to the VariablesUser-Defined Variables and click New:Custom_task_en_1.png

2. In the window opened, click the Variable Configuration block and select Custom JavaScript as the variable type:Custom_task_en_2.png

3. Name the variable a customTask. In the Custom JavaScript window, paste the OWOX BI tracking code:Custom_task_en_3.png

You can find the code on your user behavior data pipeline under Settings > JavaScript code for hit and session data collection or copy it below:

function() {
return function(tracker){
if("undefined"===typeof tracker.get("OWOXBIStreaming")){var f=tracker.get("sendHitTask"),h=function(){function d(c){var a=!1;try{document.createElement("img").src=e(!0)+"?"+c,a=!0}catch(k){}return a}function e(c){var a="https://google-analytics.bi.owox.com/"+encodeURIComponent(tracker.get("trackingId"));c||(a+="?tid="+encodeURIComponent(tracker.get("trackingId")));return a}return{send:function(c){var a;if(!(a=2036>=c.length&&d(c))){a=!1;try{a=navigator.sendBeacon&&navigator.sendBeacon(e(),
c)}catch(g){}}if(!a){a=!1;var b;try{window.XMLHttpRequest&&"withCredentials"in(b=new XMLHttpRequest)&&(b.open("POST",e(),!0),b.setRequestHeader("Content-Type","text/plain"),b.send(c),a=!0)}catch(g){}}return a||d(c)}}}();tracker.set("sendHitTask",function(d){f(d);h.send(d.get("hitPayload"));tracker.set("OWOXBIStreaming",!0)})}}
}

Note: You can't use more than one customTask in a single GTM tag. The function of each new customTask overrides the function of the previous one.
If it's crucial for you to use several customTask functions in a single tag, you can join their JavaScript code within a single customTask.
Remember, that modifying the OWOX BI tracking code can lead to data collection issues.

4. Click Save to add the code to the customTask variable. 

Step 2

Add your customTask variable to the Fields to Set section of each Universal Analytics tag that you're using to send data to BigQuery.

Note: To collect complete data that includes all the website events, add the customTask field to all your Universal Analytics tags. For example, goals or transaction tracking tags, etc.

1. Go to a Universal Google Analytics tag and click Tag Configuration:Custom_task_en_4.png

2. Select More settings > Fields to set > + Add Field. Enter customTask in the Field name and {{customTask}} in the Value fields:Custom_task_en_5.png

3. Click Save.

Important!It is highly recommended to check your website Content Security Policy. To run custom code added by users, the two listed GTM domains must be whitelisted on your website server. Make sure your Content-Security-Policy Header includes the script-src directive with the unsafe-inline and unsafe-eval keywords as follows: script-src 'unsafe-eval' 'unsafe-inline' https://tagmanager.google.com/  https://www.googletagmanager.com/ This directive is absolutely necessary for the correct work of the OWOX BI code.

Step 3

After you edit and save Universal Analytics tags, make sure they work properly prior to publishing the container. 

To do it, enable Preview Mode for the current workspace. Then, go to your website and make a few test clicks on a website page. To review the testing results, use GTM debug console window at the bottom of your browser. Select Click event in the left column, then switch to the Variables tab in the top navigation. Search for customTask variable in the list.  If the customTask variable is configured properly, it will contain the value 'Function'

customTask_function.png

Note:If the customTask variable contains the value 'Undefined', make sure you complete Step 1 and Step 2 described above. Please check out the possible reasons for the customTask doesn't work: OWOX BI code snippet is copied incorrectly into the customTask; more than one customTask is used in a single GTM tag; GTM domains are not allowed on your website server.

Step 4

If the GTM tags configured properly, publish the container. 

Then go to your user behavior data pipeline page in OWOX BI and click the specified Google BigQuery dataset link:

Custom_task_en_6.png

If the code is integrated correctly, a "streaming_" table will appear in the dataset. The table should receive first hit data within 2 through 5 minutes after you've updated your Google Tag Manager container.

In 24 hours after the code integration, you will see the Data collected status next to the previous day statistics under the Hits tab:Custom_task_en_7.png

After another 24 hours, you'll see a notification about the session data collected under the Sessions tab. The session data will also be available in your Google BigQuery dataset in a separate table.

Note: If you see any discrepancies between Google Analytics and OWOX BI/Google BigQuery data after setting up the data collection, please check out this article on the possible reasons for data discrepancy. 

Other data collection use cases

Send data to Google BigQuery only and block Google Analytics tracking

This can be useful if you want not to exceed Google Analytics limits or if your website generates more hits than GA can receive and you don't need to collect incomplete data there.

If it is your case, the code snippet listed below must be applied instead of the integration code from the pipeline page. Copy the following code for sending data to Google BigQuery only into the customTask:

function() {
return function(tracker){
if("undefined"===typeof tracker.get("OWOXBIStreaming")){var f=tracker.get("sendHitTask"),h=function(){function d(c){var a=!1;try{document.createElement("img").src=e(!0)+"?"+c,a=!0}catch(k){}return a}function e(c){var a="https://google-analytics.bi.owox.com/"+encodeURIComponent(tracker.get("trackingId"));c||(a+="?tid="+encodeURIComponent(tracker.get("trackingId")));return a}return{send:function(c){var a;if(!(a=2036>=c.length&&d(c))){a=!1;try{a=navigator.sendBeacon&&navigator.sendBeacon(e(),
c)}catch(g){}}if(!a){a=!1;var b;try{window.XMLHttpRequest&&"withCredentials"in(b=new XMLHttpRequest)&&(b.open("POST",e(),!0),b.setRequestHeader("Content-Type","text/plain"),b.send(c),a=!0)}catch(g){}}return a||d(c)}}}();tracker.set("sendHitTask",function(d){h.send(d.get("hitPayload"));tracker.set("OWOXBIStreaming",!0)})}}
}

Collect special values to Google BigQuery only

Google Analytics's tracking code doesn't process some specific parameters like phone numbers or emails. Yet, if you need to collect this data to Google BigQuery only, you can create a separate Google Tag Manager tag with a customTask. Read this article to learn more.

Was this article helpful?
0 out of 2 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.