npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wll-web-sdk

v0.4.1

Published

Web SDK for collecting 1st party User Data from a variety of web touch points and integrating with White Label Loyalty's platform

Downloads

1,170

Readme

npm npm bundle size

For Clients

Install

$ npm install wll-web-sdk

Or import the minified packages from CDN

# Add these lines at the top of your <body> or <head> in your HTML webpage

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/fingerprint2.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/geolocator/2.1.5/geolocator.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/wll-web-sdk@<LATEST-VERSION>/dist/wllwebsdk.umd.production.min.js"></script>

You can also just download these js files and place them in your website's js folder

Usage

1. Initialize the SDK: init(apiKey: string, campaignId: string, callback)

Do this at the beginning of your webpage

var wll = new WllWebSdk.WllWebSdk(); // Get the object
var apiKey = "abc123"; // API Key that you got during registration
var env = "PROD"; // Decides whether this is 'live' data or being used for just testing. You can choose between STAGING, PROD and DEV (only useful for contributors/developers)
var campaignId = "Campaign100"; // An ID assigned by the client (you) to uniquely identify this campaign website.
// Helps track which campaign website the user visited.

// Initialize the SDK
const userToken = wll.init(apiKey, campaignId, env
    (error, userToken) => 
    {
      if (error) {
        console.log(error);
      } else {
        console.log(userToken); // Ignore, a non-null value is enough to know that the SDK was correctly initialized.
        // FYI, userToken is used internally to ID a unique visitor.
      }
    });

2. Get User Details: getExistingUser()

Returns the UserProfile already fetched, if available.

  • Use this after the init() method to check if the WLL SDK was able to correctly identify the user just based on the UserToken.
  • You can also use this to get access to the UserProfile object at any time, for eg, once the user has submitted their email address.
let userProfile = wll.getExistingUser();
if (userProfile) {
  console.log("Welcome: " + userProfile.emailAddress);
}

UserProfile

UserProfile is a unique profile corresponding to a real-world user. The primary identifier is the email address. WLL SDK progressively builds the UserProfile as a visitor visits multiple campaign websites maintained by the tenant and shares their personal information.

NOTE: The UserProfile object returned by the SDK only contains the field 'emailAddress'. This can be used to personalize the webpage to welcome the user, or to skip email address form entry.

export interface UserProfile {
    emailAddress: string, // Mandatory with every UserProfile submission
    givenName?: string, // First name
    familyName?: string; // Last name
    telephoneNumber?: string;
    extraFields?: { [key: string]: any }; // Key Value Pairs of any fields needed for more User information
}

3. Submit email address/Sign up using email address: signupUsingEmail(emailAddress: string, callback)

Submits an email address to uniquely identify the visitor, and links the visitor's activity to an existing UserProfile.

If the getExistingUser() method doesn't return a UserProfile after initializing the SDK, the White Label Loyalty system hasn't been able to uniquely identify the visitor. In order to link this visitor's activities to an existing UserProfile (or create a new one, in case a UserProfile doesn't exist in the WLL system), the SDK needs an email address of the user, at least.

NOTE: The WLL Web SDK doesn't handle email address verification, and if needed, would have to be handled by the client.

wll.signupUsingEmail(emailId, (error, userProfile) => {
      if (error) {
        console.log(error);
      } else {
        console.log(userProfile);
        userProfileSubmitted = userProfile;
        alert("This email ID was submitted: " + userProfileSubmitted.emailAddress);
      }
    });

4. Fill and submit user profile information: fillUserDetails(userProfile: UserProfile, callback)

Submits user information to update existing UserProfile fields in the WLL system. Works by appending fields to the existing UserProfile in the backend. If a UserProfile field submitted has a different (non-null) value than the one in the backend, the new value overrides the older value.

NOTE: If you only want to ask the user to submit their email Id, use the signupUsingEmail() method. If you need email Id and other profile details, use this method.

// ExtraFields is a map of key-value pairs depending on the client's needs
const extraFields = {
  policyNumber: policyNumber && policyNumber.length > 0 ? Number(policyNumber) : undefined ,
  addressStreet,
  addressCity
}

// Eg: Build the userProfile using a form
const userProfile = {
  emailAddress: userProfileSubmitted.emailAddress,
  givenName: !givenName || givenName.length === 0 ? undefined : givenName,
  familyName: !familyName || familyName.length === 0 ? undefined : familyName,
  telephoneNumber: !telephoneNumber || telephoneNumber.length === 0 ? undefined : telephoneNumber,
  extraFields
}

// Submit the userProfile
wll.fillUserDetails(userProfile, (error, userProfile) => {
  if (error) {
    console.log(error);
  } else {
    console.log(userProfile);
    userProfileSubmitted = userProfile;
    alert("This email ID's profile was submitted: " + userProfileSubmitted.emailAddress);
  }
});

5. Opt out of Profile use (Useful for GDPR compliance): setProfileAsRestricted(isRestricted: boolean = true, callback: any)

Allow user to opt out of their profile info being used.

wll.setProfileAsRestricted(true, (error, userProfile) => {
  if (error) {
    console.log(error);
  } else {
    alert("This email ID's profile was opted out: " + userProfile.emailAddress);
  }
});

For Contributors

Changing the Base URL of the APIs:

You can change the Base URL of the APIs using the environment provided during init().

export enum Environment {
    Dev = 'DEV',
    Staging = 'STAGING',
    Prod = 'PROD',
}

TSDX Bootstrap

This project was bootstrapped with TSDX.

Local Development

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.

Your library will be rebuilt if you make edits.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.