Skip to content

Instantly share code, notes, and snippets.

@phylliswong
Last active February 2, 2022 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phylliswong/bbbf9a24d7644617d0a5b9fe4a8515f2 to your computer and use it in GitHub Desktop.
Save phylliswong/bbbf9a24d7644617d0a5b9fe4a8515f2 to your computer and use it in GitHub Desktop.
FragranceX Event Emit
function sendEvent(tag, url){
try {
window.evolv.client.emit(tag);
} catch (e) {
console.log(e);
}
}
function pageMatch(page) {
if (!page) return false;
return new RegExp(page).test(location.pathname);
}
function processEvents(config){
if (!!config.events) {
// Match event keys as object values
config.events.forEach(function(event) {
var matches = pageMatch(event.page);
if (matches) {
sendEvent(event.eventKey);
}
});
} else {
// Match event keys as object keys
var events = Object.keys(config);
events.forEach(function(event){
var conditions = config[event];
var matches = pageMatch(conditions.page)
if (matches){
sendEvent(event);
}
})
}
}
module.exports = processEvents;
{
"name": "eventEmit",
"main": "eventEmit.js",
"version": "0.1.1",
"description": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment