JS SDK
Logspot SDK for browser applications built with React, Next.js, Angular, etc.
Installation
npm install @logspot/web
or
yarn add @logspot/web
Usage
Init
publicKey
- project public keycookiesDisabled
- use this property to disable anonymous user trackingcookieDomain
- use this property to set root domain (cross-domain tracking)cookieExpirationInSeconds
- use this property to define when user id should expire (by default, it’s 2 years)enableAutoPageviews
- enable auto tracking of pageviews (default: true)enableAutoClicks
- enable auto capture of user clicks (default: false)externalApiUrl
- API proxy urlonLoad
- callback function to perform actions when Logspot is loaded. E.g. register super properties before initial pagevieweventMapper
- callback function which maps tracking payload to a new payload. With it, you can adjust Logspot’s events to your needs.
Track
Parameters:
name
- event name e.g. GroupCreateduserId
(optional) - unique user id which will link the event to a specific user. It can be integer, UUID or even an email.metadata
(optional) - you can attach a JSON object to your event.notify
(optional) - triggers mobile notifcation.message
(optional | max 255 chars) - messaged displayed in the app and in the notification.
Maximum size of the payload is 3kB.
Track using CSS classes
You can also track clicks on your website by using lgspt-
classname. All clicks will be automatically tracked.
The event name will be fetched from the classname.
Above click will result in the Sign Up
event.
Super properties
You can define super properties which will be assigned to every event and pageview by calling register
method. Previous properties will be merged with new properites (the new props will overwrite the prev props).
?> Super properties will be stored in cookies for 30 days (if cookies are enabled)
Register super properties
Get super properties
Unregister super properties
You can unregister
super property when it’s not needed anymore.
Reset super properties & user id
When you want to clean up super properties and user id, use reset
method.
How to configure super properties for all events including the first pageview?
!> The first pageview is sent when the script is loaded. If we call register
after init
, the first pageview won’t have super properties.
We need to use onLoad
parameter in the sdk config. In the onLoad
, you can call register
method to register super properties for all events or any other method.
Register static properties:
or register dynamic properties with e.g. API call: