Analytics ยท Tracking triggers

The Onesecondbefore JavaScript library is only built for tracking to keep it as small as possible. This page explains how to place triggers in combination with the Onesecondbefore tracking library.

<script>
/* Onesecondbefore Analytics Start */
!function(){"use strict";var e,t,n,s,c;e=window,t=document,n="osb",e.$OSB_QUEUENAME=n,
e[n]=e[n]||function(){(e[n].q = e[n].q || []).push(arguments)},s = t.createElement("script"),
c=t.getElementsByTagName("script")[0],s.async=1,
s.src="https://storage.googleapis.com/onesecondbefore/js/osb.min.js",
c.parentNode.insertBefore(s,c)}();
/* Onesecondbefore Analytics Finish */
</script>

Track page views

Track a page view with Google Tag Manager by doing the following:

  • Login to Google Tag Manager
  • Select Tags and click New, you should now be in the screen with a blank Tag
  • Click on Tag Configuration, you should now get a list on the right side with tag templates you can choose
  • Choose Custom HTML
  • Copy and past the pageview tag in the textarea like this:
<script>
/* Onesecondbefore Analytics Start */
!function(){"use strict";var e,t,n,s,c;e=window,t=document,n="osb",e.$OSB_QUEUENAME=n,
e[n]=e[n]||function(){(e[n].q=e[n].q||[]).push(arguments)},s=t.createElement("script"),
c=t.getElementsByTagName("script")[0],s.async=1,
s.src="https://storage.googleapis.com/onesecondbefore/js/osb.min.js",
c.parentNode.insertBefore(s,c)}();
/* Onesecondbefore Analytics Finish */
</script>
  • Customize the tracking code as you see fit.
  • Add the trigger, by clicking on the section below Tag Configuration
  • Add the trigger: All pages

The tag triggers when a visitor clicks on a link leaving the website.

Put the code below in the source code of your page to track exit links. Replace the example domains in the regular expression for your own. Rule of thumb is that all domains with Factbase tracking should not be tracked as an exit link.

<script>
let comp = new RegExp('(www.mydomain.com|www.mydomain2.com)');
let links = document.getElementsByTagName('a');
for (let i = 0, i < links.length; i++) {
     if (links.[i].href && !comp.test(links[i].href)) {
         links[i].onclick = function() {
             osb('send', 'event', {
                 category: 'Exit links',
                 action: 'click', 
                 label: this.href
             });
         }
     }
}
</script>

Customize the tracking code as you see fit.

Google Tag Manager

Track a pageview with Google Tag Manager by doing the following:

  • Login to Google Tag Manager
  • Click Variables, then Configure, check the box in front of Click URL to enable it and close the window
  • Select Triggers, and press New
  • Choose Just links, and click on Some Link Clicks
  • Set the rule below like this: Click URL does not match RegEx (www.mydomain.com|www.mydomain2.com)
  • Replace the example domains for your domain(s), make sure they are separated by a pipeline (|)
  • Give the trigger the name: Exit links
  • Select Tags and click New, you should now be in the screen with a blank Tag
  • Click on Tag Configuration, you should now get a list on the right side with tag templates you can choose
  • Choose Custom HTML
  • Copy and past the pageview tag in the textarea like this:
<script>
osb('send', 'event', {
    category: 'Exit links',
    action: 'click',
    label: {{Click URL}}
});
</script>

Your don't have to put quotes (' or ") around {{Click URL}}. Customize the tracking code as you see fit.

  • Add the trigger, by clicking on the section below Tag Configuration
  • Add the trigger you just created: Exit links
  • Publish your changes! Make sure to test it before.

The tag triggers when a visitor clicks on a link to download a file.

Put the code below in the source code of your page to track downloads. .

<script>
var comp = new RegExp('\.(xls|xlsx|doc|docx|pdf|zip|exe|mp3)');
var links = document.getElementsByTagName('a');
for(var i = 0, len = links.length; i < len; i++) {
    if (!comp.test(links[i].href)) {
        links[i].onclick = function () {
            osb('send', 'event', {
                category: 'Downloads',
                action: 'click',
                label: this.href
            });
        }
    }
}
</script>

Customize the tracking code as you see fit.

Google Tag Manager

Track a pageview with Google Tag Manager by doing the following:

  • Login to Google Tag Manager
  • Click Variables, then Configure, check the box in front of Click URL to enable it and close the window
  • Select Triggers, and press New
  • Choose Just links, and click on Some Link Clicks
  • Set the rule below like this: Click URL does not match RegEx \.(xls|xlsx|doc|docx|pdf|zip|exe|mp3)
  • Add more file extensions if necessary, make sure they are separated by a pipeline (|)
  • Give the trigger the name: Downloads
  • Select Tags and click New, you should now be in the screen with a blank Tag
  • Click on Tag Configuration, you should now get a list on the right side with tag templates you can choose
  • Choose Custom HTML
  • Copy and past the pageview tag in the textarea like this:
<script>
 osb('send', 'event', {
     category: 'Downloads',
     action: 'click',
     label: {{Click URL}}
 });
 </script>

You don't have to put quotes (' or ") around {{Click URL}}. Customize the tracking code as you see fit.

  • Add the trigger, by clicking on the section below Tag Configuration
  • Add the trigger you just created: Downloads
  • Publish your changes! Make sure to test it before.