1.0.1 • Published 2 years ago

@cxsense/analytics v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

CxSense Analytics

Analytics is a client web SDK that collects customer interactions and listens to your customer journey updates.

CxSense empowers engineers to build personalised and hyper-personalised customer expriences in days instead of month. Sign up with CxSense today.

Before you start

This guide assumes you have created a free project account on CxSense. If you don't already have an account you can start by creating a free account and registering a web app to access your api_key.

Getting started

Using the Analytics package is as simple as adding this JavaScript code to your page.

import analytics from '@cxsense/analytics'

analytics.load('your_api_key');
analytics.identify("your_user_identifier");
analytics.track('plan-upgrade', { metadata: { plan: 'premium' } });

Installation

npm install @cxsense/analytics
# or
yarn add @cxsense/analytics

Anonymous users

Anonymous users can be identified by providing null as their identifier. Analytics generates an ID and store it in users browser localstorage.

analytics.identify(null);

By default, Analytics uses the same generated identifier whenever the above function is called. In case you need a new identifier you have to reset it.

analytics.reset();
analytics.identify(null);

API

Table of Contents

track

Track user interactions

Parameters

  • event string the name of the event to track.
  • properties Object event properties. (optional, default {})

    • properties.metadata Object the metadata that describes the event. (optional, default {})
    • properties.variation_settings Object additional tags and attributes that define the event. (optional, default {})
    • properties.item Object? user interactions with items in catalogues. If item provided, variation_settings will be ignored.

      • properties.item.catalogue Object The name of the catalogue.
      • properties.item.id Object The unique identifier of the item in the catalogue.

Examples

Track events with metadata

analytics.track('subscribed', {
  metadata: { email: 'foo@bar.com' }
});

Track events that are defined with attributes

analytics.track('product_view', {
  variation_settings: { plan: 'premium', rate: '5star' }
});

Track events for items in a catalogue

analytics.track('article_read', {
  item: { catalogue: 'articles', id: 'your_article_id' }
});

identify

To get started with our libraries your users needs to be identified. Users in segments are identified by a unique profile identifier in CxSense.

If the user_id is not provided, the user is considered anonymous. In this case, a user identifier will be generated and stored in the local storage.

Parameters

  • user_id string The unique user identifier in your system. If not provided, a random identifier will be generated.
  • segment Object Segment object that describes the segment the user belongs to. (optional, default {})

    • segment.title string The title of the segment.
    • segment.settings string The segment properties.
  • user_properties (optional, default {})

  • properties Object User properties. (optional, default {})

Examples

Identify a known user

analytics.identify('your_user_id', {
 title: 'my_segment_name',
 settings: {
   tenant: "customer1",
 }
}, {
  name: 'John Doe',
  age: 30
});

Identify an anonymous user

analytics.identify(null)

Returns string profileId - User unique identifier in CxSense

onJourneyCompletion

Parameters

Examples

Listen to journey completion events

analytics.onJourneyCompletion((data) => console.log(data)))

onDestinationResponse

Parameters

Examples

Listen to destination success responses

analytics.onDestinationResponse((data) => console.log(data)))

journeyCompletionCallback

Type: Function

Parameters

  • data Object The event object.

    • data.journey string The journey title.
    • data.journeyId string The journey identifier.
    • data.segment_settings Object The segment properties.
    • data.user_id string The user identifier.
    • data.user_properties Object The user properties.

destinationResponseCallback

Type: Function

Parameters

  • data Object The event object.

    • data.journey string The journey title.
    • data.segment_settings Object The segment properties.
    • data.user_id string The user identifier.
    • data.user_properties Object The user properties.
    • data.destination Object The destination properties.

      • data.destination.title string The destination title.
      • data.destination.response Object The destination response data.

load

Parameters

  • apiKey string The API key for your CxSense account.
  • options Object Options object. (optional, default {})

    • options.observer string The websocket observer. (optional, default false)

Examples

Load the library with in-app notification

analytics.load('your_api_key', { observer: true })

License

@cxsense/analytics is MIT licensed.

1.0.1

2 years ago

1.0.0

2 years ago