0.2.0 • Published 2 years ago

@gotitinc/giap_javascript v0.2.0

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

GIAP - Javascript SDK

Description

Javscript SDK for your app to communicate with Got It Analytics Platform

Usage

npm install @gotitinc/giap_javascript

Import the package

import giap from '@gotitinc/giap_javascript';

Initialize the library

Use this method to initialize and setup the SDK. All other SDK methods must be called after this one

giap.initialize('YOUR_PROJECT_TOKEN', 'THE_GIAP_SERVER_URL');

Parameters

  • projectToken: String - required - your project token
  • serverUrl: String - required - GIAP server url
  • enableLog: Boolean - optional - set to true to enable development log

Create alias

Use this method with a string representing user id (required) right after user has just signed up

giap.alias('INSERT THE USER ID');

Identify

Use this method with a string representing user id (required) right after user has just logged in

giap.identify('INSERT THE USER ID');

Track

Use a string to represent the event name (required) and a object (optional) to represent the event properties.

giap.track('Visit', { economyGroup });

Set properties for current profile

At any moment after initializing the lib, you can set custom properties for current tracking profile

giap.setProfileProperties({ fullName: 'YOUR FULL NAME' });

Modify properties for current profile

Increase: Increment/decrement a numeric property

giap.increase('propertyName', 100);

Append: Add element(s) to a list property

giap.append('propertyName', ['one', 'two']);

Remove: Remove element(s) from a list property

giap.remove('propertyName', ['two']);

Reset

Use this method right after user has just logged out

giap.reset();

Notification

GIAP Javascript SDK handles everything asynchronously. Your app can be notified about important tasks done by the SDK.

Implement the following methods for your library:

giap.notification.didResetWithDistinctId = (distinctId) => {
  console.log(`GIAP didResetWithDistinctId: ${distinctId}`);
};

giap.notification.didEmitEvents = (events, responseData) => {
  console.log('GIAP didEmitEvent: ', events);
  console.log('   Response: ', responseData);
};

giap.notification.didUpdateProfile = ({ id, props }, responseData) => {
  console.log(`GIAP didUpdateProfile: ${id} with withProperties: `, props);
  console.log('   Response: ', responseData);
};

giap.notification.didCreateAliasForUserId = (
  { userId, distinctId },
  responseData,
) => {
  console.log(
    `GIAP didCreateAliasForUserId: ${userId} withDistinctId ${distinctId}`,
  );
  console.log('   Response: ', responseData);
};

giap.notification.didIdentifyUserId = (
  { userId, distinctId },
  responseData,
) => {
  console.log(
    `GIAP didIdentifyUserId: ${userId} withCurrentDistinctId ${distinctId}`,
  );
  console.log('   Response: ', responseData);
};

Installation for Development

Prerequisites

  • Install Node.js at least version 14 on your machine

Installing

  1. Clone this repository

    git clone https://github.com/tutoruniverse/giap_javascript.git
  2. Install dependencies

    cd giap_javascript
    npm install

Available Script

Testing

npm test

Run Demo App

  1. Edit config in demo/src/constants/app.js if needed
  2. Run
npm run start-demo

Production

npm run build