@deeptaai/klaritics-web-sdk
v1.0.0
Published
Klaritics Web Analytics SDK
Readme
Klaritics Web SDK
Install through NPM
npm install --save @deeptaai/klaritics-web-sdkSDK Initialization
Import Klaritics sdk and initialize it in application root component or page
import Klaritics from "@deeptaai/klaritics-web-sdk"; // ES6
//var Klaritics = require('@deeptaai/klaritics-web-sdk'); // ES5
Klaritics.init("YOUR_SITE_ID", "YOUR_HOST_NAME", {
// Configuration options
});Configuration Options
- honorDNT: boolean [false],
- idle_time_out: number(seconds) [1800]
Note:
Contact [email protected] to get your unique SITE_ID
- Add the following import statements in your root component or page. Make sure you add lint ignore lines for both of these lines, if you use
lint
APIs
UserId
A unique user identifier that you can assign to the user
Usage:
Klaritics.setUserId(String);Example:
Klaritics.setUserId("[email protected]");PageView
You can log a page view event when users navigate through your website
Usage:
Klaritics.logPageView(String); //String URL pathnameExample:
Klaritics.logPageView("/about.html");App Events
Usage:
Klaritics.logEvent(eventName, eventProperties);Example:
Klaritics.logEvent("ADD_TO_CART", {
userId: "[email protected]",
value: 1299,
item: "Sony Head Phone 1201"
});User Properties
Usage:
Klaritics.setUserProperties({
userProperty1: "value1",
userProperty2: "value2"
});Example:
Klaritics.setUserProperties({
gender: "Male",
age: 24,
isPaidUser: true,
creditsLeft: 250
});Session Properties
Usage:
Klaritics.setSessionProperties({
property1: "value1",
property2: "value2"
});Example:
Klaritics.setSessionProperties({
language: "en",
location: "Hyderabad"
});Get Client Id
Use this API to get the unique identifier that Klaritics SDK generates for this user
Example:
const clientId = Klaritics.getClientId();Start New Session
Starts new session if there is no active session. If a session is already in progress, it acts as a no-op
Klaritics.startNewSession();End Session
Ends the active session if any active session in progress. After this call, none of the Klaritics APIs work, except startNewSession() API.
Klaritics.endSession();Handle Deeplink Redirection
For single page applications built with React/Angular/Vue, you need to handle the internal redirection on your own by using the setRedirectionHandler method.
Example
Klaritics.setRedirectionHandler((url) => {
// Interpret the URL and redirect user to the specific URL
});