1.2.0 • Published 6 years ago

kentico-cloud-tracking v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

npm version Build Status npm Gzip browser bundle

Kentico Cloud Tracking SDK

A client library for manually tracking visitor data with Kentico Cloud in Node and browsers. Abstracts calls to the Kentico Cloud Tracking API. For more information, see the Tracking API Reference.

The library supports ES2015 and is fully written in TypeScript.

Installation

npm i rxjs --save
npm i kentico-cloud-tracking --save

Initialization

import { TrackingClient } from 'kentico-cloud-tracking';

const client = new TrackingClient({
    projectId: 'xxx',
);

Usage with RxJS (recommended)

We strongly recommend using Observable instead of Promise as observables support all that Promises too, and much more. Using Observables is especially important if you are building any modern application (for example, single page apps with React or Angular) as it allows you to easily cancel, merge, flatten or retry requests.

After creating a subscription, don't forget to unsubscribe when you don't need the result anymore (for example, when navigating to a different page).

// Starts a new session
client.recordNewSession({
    sid: '111114cc62300000',
    uid: '1111136b4af00000',
})
    .getObservable()
    .subscribe();
    
// Record a custom activity
client.recordCustomActivity({
    sid: '111114cc62300000',
    uid: '1111136b4af00000'
  }, 
"Clicked_facebook_icon")
  .getObservable()
  .subscribe();


// Creates a contact profile
client.createContactProfile({
  sid: '111114cc62300000',
  uid: '1111136b4af00000',
  email: "john.snow@wall.north",
  name: "John Snow",
  company: "Night's Watch",
  phone: "444-256-487",
  website: "http://gameofthrones.wikia.com/wiki/Jon_Snow"
})
  .getObservable()
  .subscribe();

Usage with Promise

For whatever reason, you can still use good old Promises:

client.recordNewSession({
    sid: '1111136b4af00000',
    uid: '111114cc62300000',
})
    .getPromise()
    .then();

Client configuration

Propertytypedescription
projectIdstringProjectId of your Kentico Cloud project
enableAdvancedLoggingbooleanIndicates if advanced (developer's) issues are logged in the console. Enable for development and disable in production.
baseUrlstringCan be used to configure custom base URL (e.g., for testing)
retryAttemptsnumberNumber of retry attempts when an error occurs. Defaults to '3'. Set to '0' to disable.
httpServiceIHttpServiceCan be useud to inject custom http service for performing requests

Analytics