Last active
December 5, 2019 23:25
-
-
Save frankiehayward/b8fe2adb23a69d9bdf9af90f93fa6455 to your computer and use it in GitHub Desktop.
This is a template prototype for the Sojern tracking script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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