This feature is available only with paid Kochava accounts. Contact us to learn more.
If you have already integrated the SDK and started it, please visit Using the SDK and choose a topic.
Integrating the SDK
Requirements:
- Google Tag Manager
Supported Platforms:
- Web (Browser)
Data Privacy:
Integration
Follow the steps below to integrate the Kochava Web SDK using Google Tag Manager:
- In the Google Tag Manager UI, click Add a new tag.
- Click Tag Configuration.
- Choose Tag Type > Custom > Custom HTML.
- Prepare the SDK script:
<script>function loadScript() {
if (window.kochava) {
console.log("Kochava snippet already included");
return
}
var scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
var kochavaScript = document.createElement("script");
kochavaScript.type = "text/javascript";
// To disable caching, change this value to true
var disableCaching = false;
kochavaScript.src =
(disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
kochavaScript.async = true;
kochavaScript.onload = function() {
// YOUR CODE HERE
};
document.head.appendChild(kochavaScript);
}
loadScript();</script>
Starting the SDK
Once you have added the Kochava SDK to your project, the next step is to create and start the SDK class in code. Only your App GUID is required to start the SDK with the default settings, which is the case for typical integrations.
Kochava recommends starting the SDK as soon as the application starts, although this can be done later if needed. Starting the tracker as early as possible will ensure it is started before use, resulting in more accurate data/behavior.
Where your web page starts:
- (Optional) Make any desired pre-start configuration calls (registerIdentityLink, disableAutoPage, useCookies etc).
- Call startWithAppGuid using a valid Kochava App GUID.
Edit the snippet you included earlier to the following:
<script>function loadScript() {
if (window.kochava) {
console.log("Kochava snippet already included");
return
}
var scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
var kochavaScript = document.createElement("script");
kochavaScript.type = "text/javascript";
// To disable caching, change this value to true
var disableCaching = false;
kochavaScript.src =
(disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
kochavaScript.async = true;
kochavaScript.onload = function() {
// YOUR CODE HERE
window.kochava.startWithAppGuid("YOUR_APP_GUID");
};
document.head.appendChild(kochavaScript);
}
loadScript();</script>
Optional Configuration
From here on, the SDK is integrated and ready, the following configuration calls are optional, and are only for special desired SDK behavior. The following code snippets should be placed at in the above snippet, at the comment labeled Optional pre-start calls will go here
.
Call this function with an argument of true to stop the SDK from automatically signaling a page event when the SDK starts.
<script>function loadScript() {
if (window.kochava) {
console.log("Kochava snippet already included");
return
}
var scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
var kochavaScript = document.createElement("script");
kochavaScript.type = "text/javascript";
// To disable caching, change this value to true
var disableCaching = false;
kochavaScript.src =
(disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
kochavaScript.async = true;
kochavaScript.onload = function() {
// Auto pages will be sent (default)
window.kochava.disableAutoPage(false);
// Auto pages will not be sent
window.kochava.disableAutoPage(true);
window.kochava.startWithAppGuid("YOUR_APP_GUID");
};
document.head.appendChild(kochavaScript);
}
loadScript();</script>
Call this function with an argument of true to drop the Cookie on the website to track a device across sub-domains.
<script>function loadScript() {
if (window.kochava) {
console.log("Kochava snippet already included");
return
}
var scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
var kochavaScript = document.createElement("script");
kochavaScript.type = "text/javascript";
// To disable caching, change this value to true
var disableCaching = false;
kochavaScript.src =
(disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
kochavaScript.async = true;
kochavaScript.onload = function() {
// Will not use cookies (default)
window.kochava.useCookies(false);
// Will use cookies
window.kochava.useCookies(true);
window.kochava.startWithAppGuid("YOUR_APP_GUID");
};
document.head.appendChild(kochavaScript);
}
loadScript();</script>
If you wish to disable caching of the SDK script, set the disableCaching variable to true.
<script>function loadScript() {
if (window.kochava) {
console.log("Kochava snippet already included");
return
}
var scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
var kochavaScript = document.createElement("script");
kochavaScript.type = "text/javascript";
// To disable caching, change this value to true
var disableCaching = true;
kochavaScript.src =
(disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
kochavaScript.async = true;
kochavaScript.onload = function() {
window.kochava.startWithAppGuid("YOUR_APP_GUID");
};
document.head.appendChild(kochavaScript);
}
loadScript();</script>
Finish Tag Integration
- Paste the snippet into the Tag Configuration.
- Click on the Triggering panel.
- Select Choose a trigger > All Pages.
- Enter a name for the tag.
- Click Save.
- Publish the new changes by clicking on Submit in the upper right corner of the screen.
- Enter the corresponding information in the version change fields.
- Click Publish.
NOTE: The tag that was just created as well as all of other previously created tags may be viewed in the Tags section.
NOTE: With your new tag set up, you can now use the Kochava Web SDK by integrating GTM into your site. Instructions on how to do so can be found here.
Confirm the Integration
Where to Go From Here:
Now that you have completed integration you are ready to utilize the many features offered by the Kochava SDK. Continue on to Using the SDK and choose a topic.