NOTE: If migrating from a previous Kochava SDK javascript snippet, be sure to remove that integration snippet and update any Kochava SDK function calls as described below.
NOTE: If you have already integrated the SDK and started it, please visit Using the SDK and choose a topic.
Integrating the SDK
Requirements:
- NodeJs
- NPM
- Vue
Supported Platforms:
- Vue
Data Privacy:
Integration:
The Kochava web SDK is available for Vue projects as a normal npm package. It provides a class called Kochava, which contains all necessary Kochava SDK functions and behavior.
- Install the Kochava SDK via NPM by running
npm install -D kochava@latest
in the root of your project directory (where package.json is located). For more installation options, see our NodeJS Web SDK Integration. - After running the command above, confirm that kochava version 3.0.1 or later was added in your package json.
Starting the SDK
In order for the SDK to start operating, the Kochava class must be instantiated one time with a valid configuration. However, Vue is a very open-ended framework with many derivatives, and so this can be accomplished in various ways. Below is one example of how this can be done, but your implementation may vary depending on your architecture. For your reference, this code example uses the default Vue 3 “setup” configuration.
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.
We recommend 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’s started before use, resulting in more accurate data/behavior.
Within your root component script tag (usually App.vue):
- Import the Kochava class.
- Create an instance of the Kochava class (we recommend calling it lower-case ‘kochava’).
- (Optional) Make any desired pre-start configuration calls (registerIdentityLink, disableAutoPage, useCookies, etc).
- Call startWithAppGuid using a valid Kochava App GUID.
- Replace
YOUR_APP_GUID
with your Kochava App GUID. For more information on locating your App GUID, refer to our Locating your App GUID support documentation.
Example — (Start Kochava in the Root Component):
// Vue3 Setup SFCs
<script setup>
import HelloWorld from './components/HelloWorld.vue';
import { Kochava } from 'kochava'; // Import the Kochava class
const kochava = Kochava.createForVue(); // Create an instance of the Kochava class
// Optional pre-start calls would go here
kochava.startWithAppGuid("YOUR_APP_GUID"); // Call startWithAppGuid
</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 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 setup>
import HelloWorld from './components/HelloWorld.vue';
import { Kochava } from 'kochava'; // Import the Kochava class
const kochava = Kochava.createForVue(); // Create an instance of the Kochava class
// Auto pages will be sent (default)
kochava.disableAutoPage(false);
// Auto pages will not be sent
kochava.disableAutoPage(true);
kochava.startWithAppGuid("YOUR_APP_GUID"); // Call startWithAppGuid
</script>
Call this function with an argument of true to drop the Cookie on the website to track a device across sub-domains.
<script setup>
import HelloWorld from './components/HelloWorld.vue';
import { Kochava } from 'kochava'; // Import the Kochava class
const kochava = Kochava.createForVue(); // Create an instance of the Kochava class
// Will not use cookies (default)
kochava.useCookies(false);
// Will use cookies
kochava.useCookies(true);
kochava.startWithAppGuid("YOUR_APP_GUID"); // Call startWithAppGuid
</script>
Vue Examples
Example — (Add the Kochava Object to a Child Component):
- Attach the kochava object to the child component in the parent’s template.
- Define the prop on the child component, call SDK functions with the kochava object.
// App.vue
<script setup>
import HelloWorld from './components/HelloWorld.vue';
import { Kochava } from 'kochava';
const kochava = Kochava.createForVue();
kochava.startWithAppGuid("YOUR_APP_GUID");
</script>
<template>
<HelloWorld :kochava="kochava"/> // Add kochava as a prop
</template>
// HelloWorld.vue
<script setup>
import { Kochava } from 'kochava'; // Import the Kochava class
// Define the kochava Prop
defineProps({
kochava: Kochava,
});
kochava.sendPageEvent("hello_world"); // Example, send a new page event
</script>
Confirm the Integration
After integrating the SDK and adding the code to start the measurement client, launch and run the app for at least 10 seconds or more. During this time the client will start and send an install payload to Kochava. To confirm integration was successful, visit the app’s Install Feed Validation page Apps & Assets > Install Feed Validation. On this page you should see one of two integration messages, indicating integration success or failure.
Integration Successful:
Along with this message you will also see a variety of data points associated with the device used for testing. At this point your integration is successful and you can proceed to the next step(s).
NOTE: It may take a few minutes for the first install to appear within the Install Feed Validation page. If you do not see this message immediately, you may simply need to wait a few minutes and check again.
Integration Not Complete:
If you encounter this message, please review the integration steps, uninstall and reinstall the app, and check again.
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.