OWOX BI tracking code integration with analytics.js on-site code (DEPRECATED METHOD)

The article will be helpful if you use legacy analytics.js counter on your site however want to set up data collection via OWOX BI. Below you will find the instructions on how to embed the OWOX BI tracking code into analytics.js.

Important!If you use Global Site Tag (gtag.js) please note that it doesn’t support the running of third-party scripts. The OWOX BI tracking code cannot be embedded into gtag.js due to this limitation.
As a solution, we recommend that you implement the OWOX BI tracking code via Google Tag Manager following these instructions

If you use a Content Security Policy, you should whitelist the OWOX BI access point on your website server before embedding the OWOX BI tracking code. To do it, add the script-src directive with the unsafe-inline and unsafe-eval keywords to your Content-Security-Policy Header as follows:
script-src 'unsafe-eval' 'unsafe-inline' https://google-analytics.bi.owox.com/ .
This directive is absolutely necessary for the correct work of the tracking code.

Default methods to set up a website data collection

Method 1: Send data to both Google BigQuery and Google Analytics

OWOX BI tracking code will be sending user behavior data to Google BigQuery and Google Analytics tracking code will keep sending them to Google Analytics.

To use this option, add these snippets to the code on each page of your website that contains a Google Analytics tracking code:

1. After the Google Analytics initialization command (ga('create', 'UA-... ); line) add:

// Connecting OWOX BI Streaming plugin to the tracker
ga('require', 'OWOXBIStreaming');

 2. After the line ga('send', 'pageview');, add:

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

 

Method 2: 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 this is your case, then add these snippets to the code on each page of your website that contains a Google Analytics tracking code:

1. After the Google Analytics initialization command (ga('create', 'UA-... ); line) add:

// Connecting OWOX BI Streaming plugin to the tracker
ga('require', 'OWOXBIStreaming');

 2. After the line ga('send', 'pageview');, add:

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

Data collection set-up when multiple Google Analytics trackers are used

If you use two separate trackers on a single page, you must name the one you use to send data to OWOX BI and adjust the OWOX BI tracking code appropriately. For example, if the tracker name is 'owox', make the following changes:

  • add ga('owox.require', 'OWOXBIStreaming'); instead of ga('require', 'OWOXBIStreaming');;
  • add ga('owox.send', 'pageview'); instead of ga('send', 'pageview');.

Code sample:

 <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-XXXXX', 'auto'); ga('send', 'pageview'); </script>
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXX', 'auto', 'owox');
// Connecting OWOX BI Streaming plugin to the tracker
ga('owox.require', 'OWOXBIStreaming'); ga('owox.send', 'pageview');
// OWOX BI Streaming plugin code
(function(){function f(g){var c=g.get("sendHitTask"),f=function(){function e(b){var a=!1;try{var d=document.createElement("img");d.src=c(!0)+"?"+b;a=!0}catch(h){}return a}function c(b){var a="https://google-analytics.bi.owox.com/"+encodeURIComponent(g.get("trackingId"));b||(a+="?tid="+encodeURIComponent(g.get("trackingId")));return a}return{send:function(b){var a;if(!(a=2036>=b.length&&e(b))){a=!1;try{a=navigator.sendBeacon&&navigator.sendBeacon(c(),b)}catch(h){}}if(!a){a=!1;var d;try{window.XMLHttpRequest&&"withCredentials"in(d=new XMLHttpRequest)&&(d.open("POST",c(),!0),d.setRequestHeader("Content-Type","text/plain"),d.send(b),a=!0)}catch(h){}}return a||e(b)}}}();g.set("sendHitTask",function(e){f.send(e.get("hitPayload"))})}var c=window[window.GoogleAnalyticsObject||"ga"];c&&c("provide","OWOXBIStreaming",f)})(); </script>
Was this article helpful?
2 out of 3 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.