Giter Club home page Giter Club logo

javascript-sdk-plugin-pending-events's Introduction

@optimizely/sdk-plugin-pending-events

BrowserStack Status

An unsupported, experimentalโš ๏ธ EventDispatcher for Optimizely Full Stack (javascript-sdk, Web browser environment) that keeps a queue of pending (not completed) events persisted to localStorage, and retries pending events on initialization.

Motivation

Tracking click in browsers is difficult because browsers often redirect users before tracking requests complete. This example suggests one of many possible solutions to the above problem. Feel free to try it out, modify according the the LICENSE, and suggest changes here. And if you have another method for tackling this problem, we'd love to hear from you! Drop us a line at [email protected].

Install

npm install @optimizely/sdk-plugin-pending-events --save

Usage

See example for an example of how this is used:

$ cd example
$ npm install
$ npm start

Load the URL provided by webpack-serve in a browser of your choice.

API

index

Construct an EventDispatcher compatible with @optimizely/optimizely-sdk

Parameters

  • localStorageKey String Key under which to persist/load pending events in window.localStorage
  • sendJSON SendJSON Function to call to send payload
  • logger Function?

Returns EventDispatcher An object with a dispatchEvent method, suitable for use as an EventDispatcher

SendJSON

Function to call to send JSON

Type: Function

Parameters

  • url String URL to send to
  • options Object
    • options.method String HTTP method to use
    • options.body String Body text (should be stringified JSON)
  • callback SendJSONCallback Function to call, with no arguments, if successful, and with Error object, if error

Examples

// Example sendJSON built using fetch
const sendJSON = (url, options, callback) => {
  const {method, body} = options;
  return fetch(url, {
    method,
    body,
    headers: {
      'content-type': 'application/json',
    }
  })
  .then((resp) => {
    if (resp.status < 400) {
      callback();
    } else {
      callback(new Error(`Bad response code: ${resp.status}`));
    }
  }, callback);
}

SendJSONCallback

Type: Function

Parameters

  • error Error? Error, if any

javascript-sdk-plugin-pending-events's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.