JS Tracker SDK Integration Guide

Overview

This documentation will detail the specifications of the javascript based SDK to track the events on your website.

It works by loading a small javascript snippet into your webpage and calling designated functions whenever you need to track an event.

Prerequisites

We assume that the initial web page where this is used is visited by clicking on an Ad Banner on Dailyhunt App.

Dailyhunt will append a parameter called dhPayload to the landing page. This parameter is crucial for the tracker to work. So, if there is any whitelist of parameters at the landing page, make sure to whitelist this parameter.

Code Snippet

Make sure to include this script in the <head> section of all the webpages you want to track events on.

note

This code snippet is self sufficient to track the page views by default.

<script>
(function(d,h,e,v,n,t,s) {
if(d.dht)
return;
n=d.dht=function() {
n.track?n.track.apply(n,arguments):n.queue.push(arguments)
}
n.queue=[];
t=h.createElement(e);
t.async=!0;
t.src=v;
t.id="dht";
s=h.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s);
}(window, document, 'script', 'https://assets-money.dailyhunt.in/dht.min.js'));
dht('init', '');
</script>

Tracking Additional Events

If you need to track additional events, you can do that using dht() function.

Syntax

dht('<eventName>', <eventData>);

Parameters

ParameterDataTypeScopeDescriptionExample
eventNamestringrequiredName that you need this event to be identified with.PageView

AddToCart
eventValueobjectoptionalData - in json format - to be associated with the event.{userId: "1", gender: "M"}

Examples

// Track 'PageView' event with a url field.
dht('PageView', {url: "https://xyz.com/page/to/track"});
// Track 'Login' event with userId and loginMode fields.
dht('Login', {userId: "121412312", loginMode: "google"});
// Track 'AddToCart' event with productId and productCategory fields.
dht('AddToCart', {productId: "121412312", productCategory: "fashion"});
Please note

If you have difficulty in any of the above steps of this guide, feel free to contact ads-tech-team@verse.in. We will get back to you as soon as possible.