@primedata/analytics-js

1.0.6 • Public • Published

Prime Data - Web JS SDK

Prime Data - JS SDK tracking event

JavaScript Style Guide Build Status Security Rating Bugs Lines of Code Coverage Code Smells Quality Gate Status

Prime Data Web Tracker Javascript Library

This package can be used in a Javascript application to interact with Prime Data.

Quick Start

Install library

# npm
npm install @primedata/analytics-js
# yarn
yarn add @primedata/analytics-js

Usage

Assuming some express-like web framework.

import Analytics from '@primedata/analytics-js'

// or, if you use require:
const Analytics = require('@primedata/analytics-js')

Implicit page view event

In the initialize call, the tracker will generate an implicit page view event, which by default will be populated with the following information:

    window.digitalData.page = window.digitalData.page || {
        path: location.pathname + location.hash,
        pageInfo: {
            pageName: document.title,
            pageID : location.pathname + location.hash,
            pagePath : location.pathname + location.hash,
            destinationURL: location.href
        }
    }

Now if you want to provide your own custom page information for the initial page view, you can simply do it like this:

// configuration
const primeJsOpts = {
    scope: '<SOURCE_KEY>',
    url: 'https://dev.primedata.ai/powehi',
    writeKey: '<WRITE_KEY>',
    initialPageProperties: {
        pageInfo: {
            destinationURL: window.location.href
        }
    },
    detectAdBlock: {
        enable: true,
        bannerMessage: "You are on the ad blocker. Our feature does not work well when your ad blocker is enabled on this site. To fully enjoy the service, please disable the ad blocker on our site. We guarantee that there will be no ads on our site.",
        closeButtonLabel: "close"
    }
}

// instantiation
const analytics = Analytics.initialize({"Prime Data": primeJsOpts})

Also note that the FIRST call to analytics.page() will be IGNORED because of this initial page view. This is the way that the Analytics.js library handles it. So make sure you are aware of this when calling it. This is to avoid having two page views on a single call and to be compatible with old versions that did use the explicit call.

Sending events

Here are some examples of sending events :

analytics.page() // first call will be ignored as the initial page load is done in the initialize method

analytics.identify("af285fa381f77778ec427c01d48764b863c14705", {
    phone_number: '0985490107',
    full_name: 'Nguyen Le Phong',
    email: 'nguyenlephong@primedata.ai'
});

analytics.track('page_viewed', {
    title: 'How to Create a Tracking Plan',
    course: 'Intro to PrimeData CDXP'
});

As the PrimeData Tracker uses the Analytics.JS API, you can find more information about it here. All methods can be used on analytics object, although not all event types are supported by PrimeData integration.

Package Sidebar

Install

npm i @primedata/analytics-js

Weekly Downloads

0

Version

1.0.6

License

Apache-2.0

Unpacked Size

906 kB

Total Files

8

Last publish

Collaborators

  • primedata.ai