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.
var arr = [];
sq = sq || function() {
arr.push(arguments);
};
sq.arr = sq.arr || arr;
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);
};
stackqueue.flush(window.sq, { log: log });