1.0.5 • Published 10 months ago

nextuser_sdk v1.0.5

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

nu-ts-tracker

Nextuser's tracking lib

Installation

npm install nextuser_sdk

Usage

//Import
import {nextuser, NUUser, NUUserGender, NUCart, NUCartItem, NUPurchaseDetails} from 'nextuser_sdk';

//Initialize Nextuser
var tid = 'internal_tests'; // your website id on Nextuser's Platform
nextuser.init(tid);

//Track Event
var event = '_my_first_event'
nextuser.track(event); // track event name
nextuser.track(event, 1, 2, 'sales'); // track event name + parameters (up to 10 parameters allowed)

//User Identification
var user = new NUUser();
user.email = 'a.lazea@gmail.com';
user.uid = '12345';
user.firstname = 'Ben';
user.lastname = 'Kenoby';
user.gender = NUUserGender.M;

nextuser.identify(user);

//User's variables tracking
var variables = {
	"var1":"val1",
    "var2":"val2"
};
nextuser.trackUserVariables(variables); // track user's variables, key/value pair of variableName/variableValue

//Cart

//Add to Cart
var cartItem = new NUCartItem();
cartItem.id = "123";
cartItem.quantity = 5;
cartItem.name = "product_name";
cartItem.category = "product_category";
cartItem.description = "product_desc";
nextuser.addToCart(cartItem); // adds a product to cart (if this product is already in the cart it's quantity value will be replaced by the current one)

//Remove from Cart
var productId = "123";
nextuser.removeItemFromCart(productId); // remove product with this id from cart

//Track Purchase
var cartTotal, details;

details = new NUPurchaseDetails();
details.discount = 200;
details.shipping = 1200;
details.tax = 300;
details.currency = "$";
details.incomplete = false;
details.paymentMethod = "card";
details.affiliation = "affiliation";
details.state = "MM";
details.city = "BM";
details.zip = "123456";

cartTotal = 1000;

nextuser.trackPurchase(cartTotal, details); // track purchase

//Browsed Products
nextuser.trackViewProduct(id); // track product browsed with this id 
1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago