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

ee-pltv

v2.0.4

Published

A library for converting userAgent, geo and course into single LTV value.

Downloads

417

Readme

Enrollment Engine Predictive Lifetime Value

A libary for caculating a users ltv based on userAgent, geo and course.

Installation

npm install

Usage

You will need to set a window variable called _eePltvConfigV2. The variable must be a javascript object and has only one key to set which is onLoad. This is a callback that will be executed as soon as the library is loaded. The onLoad will return an API object with the following methods:

  • uaToDeviceType: takes a user agent string as an argument and returns the device type based on https://github.com/faisalman/ua-parser-js.
  • uaToOSName: takes a user agent string as an argument and returns the OS name based on https://github.com/faisalman/ua-parser-js.
  • initSentry: takes the Sentry Dsn string key as an argument and initializes Sentry on the landing page, which will capture when our EE server fails to respond.
  • calculatePltv: takes an URL string and a user agent string as the arguments and returns an object containing three properties: pltv, default_value and debug_mode. The value of pltv is the predictive lifetime value. default_value is a boolean indicating whether pltv value is the calculated by the ML endpoint or a default one. debug_mode is a boolean configured on a program level and its purpose is to determine whether the fb purchase event should be sent or not according to the pltv correctness. For Halfsies project you also need to pass an extra param entryToken when calling the method. You will get this token on the queryparams of URL after the Native Form POST response.

See below for a typical usage for Halfsies Project. The use of the keywords async and await are recommended here because the LandingPageTemplate js is compiled on the EE so they are supported. In case you also want to use these where the js is not compiled you need to use Promises instead, so check the example for the Marketing Thank You pages.


/* On LandingPageTemplate.js*/
import { API } from 'ee-pltv'

afterSubmit: async () => {

  window._eePltvConfigV2 = {
    ...window._eePltvConfigV2,
  }
  try {
    API.initSentry(sentryDsn);
    const pltvData = await API.calculatePltv({
      urlString: window.location.href,
      uaString: window.navigator.userAgent,
      entryToken,
    });
    console.log('this is the response from PLTV ', pltvData.pltv);
  } catch (error) {
    console.log('an error occurred', error);
  } finally {
    /*
      If there is a redirect path set then use it. If not then reload the page.
    */
  }
}


/* If you want to test it pointint to staging, then on LandingPageTemplate.html.erb */
<% if ENV['PLTV_STAGING_URL'] %>
  <script>
    window._eePltvConfigV2 = {};
    window._eePltvConfigV2.PLTV_URL = "<%= ENV['PLTV_STAGING_URL'] %>"
  </script>
<% end %>

Now see below for a typical usage on the Marketing Thank You pages


window._eePltvConfigV2 = {
  onLoad: function (API) {
    API.initSentry(sentryDsn);
    API.calculatePltv({ urlString: window.location.href, uaString: window.navigator.userAgent })
      .then(function (pltvData) {
        console.log('this is the response from PLTV ', pltvData.pltv);
      }).catch(function (error) {
        console.log('an error occurred', error);
      })
  },
};

var ee_head = document.getElementsByTagName('head')[0];
var ee_script = document.createElement('script');
ee_script.type = 'text/javascript';
ee_script.async = true;
ee_script.src = 'https://<link-to-version-on-CDN>';
ee_head.appendChild(ee_script);

Start Dev Server

npm start

This command opens a HTML file with the development script.

Build Prod Version

npm run build

Testing production version

After builiding the script with the npm run build command, the file dist/ee-pltv.js will be accessible.

To run the production script in a local HTML file run open ./playground/dist-index.html

Features: