Capture · Installation

JavaScript

The JavaScript tracking snippet needs a library to be included on every HTML page. The code should be added near the top of the <head> tag and before any other script or CSS tags. This second version of the JavaScript tracking library consists of two different libraries based upon the browser's capabilities:

  • An improved module variant used by modern desktop browsers (e.g. current Chrome, Firefox, Edge, and Safari) and mobile browsers (e.g. Chrome and Firefox for Android, Safari for iOS 10.3+). This amounts to at least 95% of all traffic. This variant uses modern JavaScript features, like module, ES2015, Promises, async / await and does not need any poly-fills or workarounds for missing JS features. Its accuracy is hence higher and therefore tracks a higher percentage of visitors. See caniuse.com for an overview which browsers can use this improved library.
  • A nomodule variant used by older browsers (e.g. Internet Explorer 8-11) and older mobile browsers.

To install both versions, use the following code:

<script nomodule>
!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)}();

// Commands follow...
</script>
<script type="module" crossorigin="use-credentials">
import osb from "https://storage.googleapis.com/onesecondbefore/js/osb.min.mjs";

// Commands follow...
</script>

Note the difference in the file names osb.min.js vs. osb.min.mjs.

After this script inclusion you can add statements to call the command queue, either using a Tag Manager or by including them in each respective block. This indeed does duplicate the calls but the module is running asynchronously and any calls to osb(...) might not yet be available if they're running outside of the <script type="module" crossorigin="use-credentials"> fragment.

Get the latest version

The latest version is 6.0. It was last updated in January 2021.

Download the latest version here

Customization

You can customize the loading of the JavaScript tracking library.

Non-module version

For the legacy version of the library you can replace the following variables:

  • https://storage.googleapis.com/onesecondbefore/js/osb.min.js = location of the tracking library.
  • osb = Global name of the command queue. Rename this method if you want to give the function a different name.

Module version

The module version has a few more capabilities for customization by adding querystring parameters to the obs.min.mjs import statement. If the module is not loaded from storage.googleapis.com, the trackerUrl is automatically set to this same URL as well. This is useful for projects that run Capture under their own domain name. The following querystring parameters are supported:

NameDescription
nameName of global JavaScript variable where command queue is made available, default 'osb'.
aidAccount id, same as used in 'create' or 'config' commands, default 'development'.
sidSite id, same as used in 'create' or 'config' commands, default undefined.
nsNamespace, same as used in 'create' or 'config' commands, default undefined.
isIP settings, same as used in 'create' or 'config' commands, default 1.
csCookie settings, same as used in 'create' or 'config' commands, default 0.
esError sampling. If set > 0 and <= 100, the percentage of javascript errors that will be sent the capture server using a window.addEventListener('error', ...) callback and reported as a 'JS Error' event. Default 0 (no errors will be collected).
sendSpecify 'pageview' to also trigger a pageview event.

Using some or all of the above parameters would remove the need for the osb('create', ...) command.

<script type="module" crossorigin="use-credentials">
import osb from "https://storage.googleapis.com/onesecondbefore/js/osb.min.mjs?" +
    "aid=example&sid=mysite.web&is=2";
// More commands
</script>

// Is similar to:
<script type="module" crossorigin="use-credentials">
import osb from "https://storage.googleapis.com/onesecondbefore/js/osb.min.mjs";
osb('create', 'default', {
    accountId: 'example',
    siteId: 'mysite.web',
    ipSettings: 2
});
// More commands
</script>
<script type="module" crossorigin="use-credentials">
import osb from "https://storage.googleapis.com/onesecondbefore/js/osb.min.mjs?" +
    "aid=example&sid=mysite.web&is=2&send=pageview";
</script>

// Is similar to:
<script type="module" crossorigin="use-credentials">
import osb from "https://storage.googleapis.com/onesecondbefore/js/osb.min.mjs";
osb('create', 'default', {
    accountId: 'example',
    siteId: 'mysite.web',
    ipSettings: 2
});
osb('send', 'pageview');
</script>
<script type="module" crossorigin="use-credentials">
import osb from "https://storage.googleapis.com/onesecondbefore/js/osb.min.mjs?" +
    "name=myosb&aid=example&sid=mysite.web&is=2";
</script>

// now you can use myosb('send', 'event', ...) instead of osb('send', 'event', ...)
<a href="..." onclick="myosb('send', 'event', '...')">Click</a>
<script type="module" crossorigin="use-credentials">
import osb from "https://storage.googleapis.com/onesecondbefore/js/osb.min.mjs?" +
    "es=50";
</script>

// 50% of below JS errors will be reported as a 'JS Error' event
alert(doesnotexist);

Android

Add the following repository and dependency to your app's build.gradle file:

repositories {
    ...
    maven {
        url "https://www.onesecondbefore.com/repository"
    }
}

dependencies {
    ...
    implementation 'com.onesecondbefore.tracker:tracker-android:1.0.0'
}

After installation, consult our mobile reference documentation. Need help? Contact support.

iOS

Prerequisites

  • Deployment Target iOS 9.0 or later.
  • Xcode 10.1 and iOS SDK 12 or later.
  • iPhone, iPad or iPod touch.

Integration via CocoaPods

The OSB SDK can be integrated via CocoaPods.

target '[Your Target Name]' do
pod 'onesecondbefore-tracker'
end

Import the SDK into your code

Use import OSB. We don't require any additional bridging header to use this pod file.

After installation, consult our mobile reference documentation. Need help? Contact support.

React Native

Contact support.

This website uses cookies to ensure you get the best personal experience.