Wondering what’s next for npm?Check out our public roadmap! »

@sajari/stackTypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Stack

This stack queue replicates async function like the one used in the Google Analytics (GA) snippet.

Where this comes in handy is putting javascript snippets on html pages without requiring external scripts. The ability to push data and events into a queue before a larger javascript file is loaded is invaluable in certain circumstances.

The code required to set up a stack queue object that is compatible with this library is minimal.

Browser

Usage like newer Google Analytics, wrapped in a function.

// Setup
var arr = [];
sq = sq || function() {
  arr.push(arguments);
};
sq.arr = sq.arr || arr;
 
// Usage
sq("log", "hello from stack!");

App

From our app we can treat the stack queue object as if it were created by the library.

var stackqueue = require("stackqueue");
 
var log = function(message) {
  console.log(message);
};
 
// Here we grab the sq declared in our html and initialise it.
stackqueue.flush(window.sq, { log: log });
 
// Output: "hello from stack!"

Install

npm i @sajari/stack

DownloadsWeekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

5.84 kB

Total Files

10

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar