Skip to content

Instantly share code, notes, and snippets.

@frankiehayward
Last active December 5, 2019 23:25
Show Gist options
  • Select an option

  • Save frankiehayward/b8fe2adb23a69d9bdf9af90f93fa6455 to your computer and use it in GitHub Desktop.

Select an option

Save frankiehayward/b8fe2adb23a69d9bdf9af90f93fa6455 to your computer and use it in GitHub Desktop.
This is a template prototype for the Sojern tracking script.
// Add Permissions
const map = require('makeTableMap');
const log = require('logToConsole');
const send = require('injectScript');
// Get Properties
const props = data.propertyList ? map(data.propertyList, 'name', 'value') : {};
// Build Url
let url = '//beacon.sojern.com/pixel/p/' + data.pixelId + '?f_v=v6_js&p_v=3';
for (let key in props) {
if (typeof props[key] !== 'undefined' && typeof props[key] !== 'object' && props[key] !== '') {
url += '&' + key + '=' + props[key];
}
}
// Log & Signal Success
const onSuccess = () => {
log('Sojern script loaded successfully.', url);
data.gtmOnSuccess();
};
// Log & Signal Failure
const onFailure = () => {
log('Sojern script load failed.');
data.gtmOnFailure();
};
// Send Pixel
send(url, onSuccess, onFailure);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment