Support Home > Web SDK Integration > JavaScript Web SDK Integration

JavaScript Web SDK Integration

This feature is available only with paid Kochava accounts. Contact us to learn more.

Feature Summary: The Kochava Web SDK is a javascript-based solution that provides marketers with Web Tracking capabilities. It can be integrated with a variety of web-based frameworks.

 

If you have already integrated the SDK and started it, please visit Using the SDK and choose a topic.


Integrating the SDK

Requirements:

  • None

 

Supported Platforms:

  • Web (Browser)

 

Data Privacy:

 

Integration:

Estimated Time to Complete
5 Minutes

(Release Notes)

 

  1. Copy the Code Snippet
  2. Paste the following code into the head of the site:

    function loadScript() {
      if (window.kochava) {
        console.log("Kochava snippet already included");
        return
      }
    
      const scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
      const kochavaScript = document.createElement("script");
      kochavaScript.type = "text/javascript";
    
    
      // To disable caching, change this value to true
      const disableCaching = false;
    
      kochavaScript.src =
        (disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
      kochavaScript.async = true;
    
      kochavaScript.onload = () => {
        // YOUR CODE HERE
      };
      document.head.appendChild(kochavaScript);
    }
    
    loadScript();

Starting the SDK

Estimated Time to Complete
1 Minute

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:

  1. (Optional) Make any desired pre-start configuration calls (registerIdentityLink, disableAutoPage, useCookies etc).
  2. Call startWithAppGuid using a valid Kochava App GUID.
  3. Edit the snippet you included earlier to the following:

    function loadScript() {
      if (window.kochava) {
        console.log("Kochava snippet already included");
        return
      }
    
      const scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
      const kochavaScript = document.createElement("script");
      kochavaScript.type = "text/javascript";
    
      // To disable caching, change this value to true
      const disableCaching = false;
    
      kochavaScript.src =
        (disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
      kochavaScript.async = true;
    
      kochavaScript.onload = () => {
        // ADD THE START CALL HERE
        window.kochava.startWithAppGuid("YOUR_APP_GUID");
      };
      document.head.appendChild(kochavaScript);
    }
    
    loadScript();

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.

function loadScript() {
  if (window.kochava) {
    console.log("Kochava snippet already included");
    return
  }

  const scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
  const kochavaScript = document.createElement("script");
  kochavaScript.type = "text/javascript";

  // To disable caching, change this value to true
  const disableCaching = false;

  kochavaScript.src =
    (disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
  kochavaScript.async = true;

  kochavaScript.onload = () => {
    // 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();

Call this function with an argument of true to drop the Cookie on the website to track a device across sub-domains.

function loadScript() {
  if (window.kochava) {
    console.log("Kochava snippet already included");
    return
  }

  const scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
  const kochavaScript = document.createElement("script");
  kochavaScript.type = "text/javascript";

  // To disable caching, change this value to true
  const disableCaching = false;

  kochavaScript.src =
    (disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
  kochavaScript.async = true;

  kochavaScript.onload = () => {
    // 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();

If you wish to disable caching of the SDK script, set the disableCaching variable to true.

function loadScript() {
  if (window.kochava) {
    console.log("Kochava snippet already included");
    return
  }

  const scriptURL = "https://storage.googleapis.com/kochava-web-assets/kochava.js/v3/kochava.min.js";
  const kochavaScript = document.createElement("script");
  kochavaScript.type = "text/javascript";

  // To disable caching, make sure this value is true
  const disableCaching = true;

  kochavaScript.src =
    (disableCaching) ? scriptURL + "?c=" + Math.random() : scriptURL;
  kochavaScript.async = true;

  kochavaScript.onload = () => {
    window.kochava.startWithAppGuid("YOUR_APP_GUID");
  };
  document.head.appendChild(kochavaScript);
}

loadScript();


Confirm the Integration

SDK WAYPOINT: At this point basic integration is complete and the Kochava SDK will begin reporting session activity and attributing installs.

 

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.

 
 
Last Modified: Oct 18, 2023 at 9:25 am