JavaScript SDK

Detailed technical documentation on the Lemnisk JavaScript SDK to send data from your website to your destinations via Lemnisk.

This document acts as a reference for the JavaScript SDK API documentation. Please ensure that you have an agreed-upon Event Tracking Plan from your Lemnisk Customer Success Point of Contact in conjunction with this document for the correct and complete implementation.

What is the Lemnisk JavaScript SDK?

Lemnisk JavaScript SDK can be used to track and send user events from your website to various destinations of your choice. These destinations can be configured in the CDP Dashboard.

Installing the Lemnisk JavaScript SDK

Add the below code to your website’s <head> section to integrate the Lemnisk JavaScript SDK.

<script type= "text/javascript"> 
window.lmSMTObj = window.lmSMTObj || [];
var methods = [
    "init",
    "page",
    "track",
    "identify"
]
for (var i=0; i<methods.length; i++) {
    lmSMTObj[methods[i]] = function(methodName){
        return function(){
            lmSMTObj.push([methodName].concat(Array.prototype.slice.call(arguments)));
        };
    }(methods[i]);

}
lmSMTObj.init("<WRITE_KEY>")

var a = document.createElement("script");
a.type = "text/javascript";
a.async = !0;
a.src = "//cdn25.lemnisk.co/ssp/st/<CAMPAIGN_ID>.js";
var b = document.getElementsByTagName("script")[0];
b.parentNode.insertBefore(a, b);
</script>

You can find your source write key in the CDP Dashboard, and the campaign ID will be provided by our delivery team.

Please make sure that you only enter the above code snippet in the website's <head> section and nowhere else. Using Lemnisk SDK with tag managers (such as GTM) is strictly not recommended. There are several reasons for that:

  • Using Lemnisk with tag managers makes it difficult to determine the root cause of technical problems, and complicates troubleshooting.

  • It may lead to loss of data while capturing the information.

  • It will lead to further delays and cause performance issues.

JavaScript SDK APIs

lmSMTObj is the global JavaScript object that is attached to the window object. You can access it in your code after initialising the JavaScript SDK. All SDK API methods are part of this object.

init() method

The init() method loads the Lemnisk JavaScript SDK with your write key.

Usage:

lmSMTObj.init("WRITE_KEY");

You need to replace WRITE_KEY with the write key in the Lemnisk CDP Dashboard.

page() method

The page() method is used to record the page details whenever a user visits the page.

Usage:

lmSMTObj.page("pageName", {properties},{otherIds}, function())

Example:

lmSMTObj.page(”home”, {
	"path": "/academy/",
	"title": "Analytics Academy",
	"url": "https://lemnisk.co"
}, {
		"trackerId": "6791c47a-0178-47bc-8711-86a2c67b2255",
}, function() {})

The properties parameter

The properties parameter of the page() call contains the below properties:

{
  path: String,
  referrer: String,
  search: String,
  title: String,
  url: String,
  keywords: Array
}

path , referrer , search , title and url are automatically collected using DOM API so you don't need to send them separately.

identify() method

The identify call lets you tie a user to their actions and record traits about them. It includes a unique User ID and any optional traits you know about the user, like their email, mobile, any other id etc.

Usage:

lmSMTObj.identify("userId", {properties}, {otherIds}, function() {})

Example:

lmSMTObj.identify(”6791c47a-0178-47bc-8711-86a2c67b2255”, {
	"firstName": "John",
	"lastName": "Doe",
	"gender": "Male",
	"age": "27",
	"city": "Mumbai"
}, {
		"email": "john.doe@gmail.com",
		"phone": "9848012345"
}, function() {})

The properties parameter

The properties parameter of the identify() call contains the below properties:

track() method

This method is used to capture user behaviour and track all actions of the user. These actions are also known as events.

Usage:

lmSMTObj.track("event_name", {properties}, {otherIds}, function() {})

Example:

lmSMTObj.track("addToCart", {
  "products": [
    {
      "name": "product_name",
      "id": "product_id",
      "category": "category_name",
      "subprod": {
        "name": "sub_product",
        "price": "40"
      }
    }
  ]
},
{
    "trackerId": "6791c47a-0178-47bc-8711-86a2c67b2255"
}, function() {});

Supported Browser Versions

If your browser supports ES5 and further versions, the SDK will be fully supported.

FAQs

This section will find answers to most of your questions and solutions to some of the most common problems you may encounter while using the Lemnisk JavaScript SDK.

Q1. Where do I find the write key for my source?

Go to CONNECT > Connections > Sources from the sidebar. Click on any source name. Click on the How to add Lemnisk to your Website? heading. You will find the Write Key present there.

Q2. How to verify if the Lemnisk JS SDK is installed correctly?

To check if the SDK has loaded correctly, open the JavaScript console in your browser:

  • Safari: Ctrl+Alt+I (Windows) or Command+Option+I (Mac) and go to the Console tab

  • Chrome: Ctrl+Shift+J (Windows) or Command+Option+J (Mac)

  • Firefox: Ctrl+Shift+K (Windows) or Command+Option+K (Mac) and select the Console tab

  • Internet Explorer: Press F12 and go to the Console tab

In the console, type lmSMTObj and press Enter. If it shows an object as shown below, it means the SDK has loaded correctly.

If the above command gives you an error Uncaught ReferenceError: lmSMTObj is not defined, it means that the SDK was not properly installed or instantiated. Refer to the installation guide to properly configure the SDK.

Q3. Can I load the SDK more than once?

Though it is technically possible to load the SDK more than once, we DO NOT recommend doing so.

Q4. Is there any size limit on the payload of the request?

No. There is no limit on the payload of the request.

Common Troubleshooting steps

In case you encounter any issues with the SDK, follow the steps below to fix the errors and run the SDK correctly.

  1. Make sure the SDK is loaded only in the <head> tag of the webpage and the SDK API methods like the page(), identify(), track() are called after the SDK is loaded.

  2. Please check whether you are running any ad blockers that prevent SDK from loading.

  3. Try clearing all cookies and cache and retry. If the problem persists, check your browser extensions or 3rd party apps that may be interacting with the network.

  4. Make sure your system date and time is correct.

  5. If nothing works, please contact us below.

Contact Us

To know more about the Lemnisk JavaScript SDK you can contact us.

Last updated