1.2.9 • Published 3 years ago

corex-analytics-sdk v1.2.9

Weekly downloads
19
License
ISC
Repository
github
Last release
3 years ago

Corex analytics SDK

The npm package of MOE tracker SDK that collects user's data and events and sends it to API.

Install

npm install corex-analytics-sdk

Usage (.init())

You should initialize the package with user national ID and the app ID , you copied when you created your app in the corex portal, inside the page the user opens after successful login , e.g if you're developing an angular app, then you should init the SDK inside ngOnInit method of the component that you redirect the user to after successful login:

import { MOE } from "corex-analytics-sdk";
...

ngOnInit() {
  ...
  MOE.init("<The user national ID>", "<The app ID>");
}

Make sure that you replace <The user national ID> & <The app ID> with the actual user's national Id and app id respectively.

Force initialization of the SDK

If you destroyed the SDK it will not be initialized again when you use init until you force it to do:

MOE.init("<The user national ID>", "<The app ID>", true);

Send stored logs on route changes (.sendStoredLogs())

You should send logs manually on route changes to correctly send logs using sendStoredLogs method for every page. This is because the SDK sends logs after it reaches specific number of logs or when the page unloads, e.g:

import { Router, NavigationStart } from "@angular/router";
...
constructor(private router: Router) {}

ngOnInit() {
...
  MOE.init("<The user national ID>", "<The app ID>");
  this.router.events.subscribe(event => {
    if (event instanceof NavigationStart) MOE.sendStoredLogs();
  })
}

The same concept applies for any other framework like React, Vue or Svelte.

Add your custom log (.on())

If you want to send additional data on the log in a specific function you can use the on method, e.g:

import { MOE } from "corex-analytics-sdk";
...

doSomeThing() {
...
  MOE.on("something happened", {
    somethingName: "Bla Bla Bla",
    somethingAuthor: "John Doe",
    ...etc
  });
}

Stop the SDK from working (.destroy())

To stop the SDK from tracking user events and session data on (logout) you can use the destroy method, e.g:

import { MOE } from "corex-analytics-sdk";
...

logoutUser() {
  ...
  MOE.destroy();
}

Changelog

  • 1.2.0 Enable user to stop the SDK from tracking user by destroy method.
  • 1.2.1 Fix bugs of destroy method.
  • 1.2.2 Optimize sending logs to the backend.
  • 1.2.3 Fix logical and syntax errors.
  • 1.2.4 Send user page cycle on page transition in sendStoredLogs method.
  • 1.2.5 Enhance on method.
  • 1.2.6 Fix user location issue.
  • 1.2.8 Fix issues and improve behaviour (force init).
  • 1.2.9 Update readme.
1.2.8

3 years ago

1.2.9

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago