* Custify plugin * @link https://getanalytics.io/plugins/custify * @link https://docs.custify.com/ * @link https://app.custify.com/settings/developer/js-snippet * @param {object} pluginConfig - Plugin settings * @param {string} pluginConfig.accountId - custify account ID * @param {boolean} [pl
(pluginConfig = {})
| 22 | * }) |
| 23 | */ |
| 24 | function custifyPlugin(pluginConfig = {}) { |
| 25 | return { |
| 26 | name: 'custify', |
| 27 | config: { |
| 28 | ...defaultOpts, |
| 29 | ...pluginConfig |
| 30 | }, |
| 31 | methods: { |
| 32 | trackTime: (pageName, idleTimer) => { |
| 33 | if (!_ctrack || typeof _ctrack.trackTime === 'undefined') { |
| 34 | return |
| 35 | } |
| 36 | _ctrack.trackTime(true, {module: pageName, idleTimer}) |
| 37 | }, |
| 38 | stopTrackTime: () => { |
| 39 | if (!_ctrack || typeof _ctrack.stopTrackTime === 'undefined') { |
| 40 | return |
| 41 | } |
| 42 | _ctrack.stopTrackTime(); |
| 43 | }, |
| 44 | setOptions: (options) => { |
| 45 | if (!_ctrack || typeof _ctrack.setOptions === 'undefined') { |
| 46 | return |
| 47 | } |
| 48 | _ctrack.setOptions(options); |
| 49 | }, |
| 50 | }, |
| 51 | initialize: ({ config }) => { |
| 52 | const { accountId, scriptInclude, options } = config |
| 53 | if (!accountId) { |
| 54 | throw new Error('No custify accountId defined') |
| 55 | } |
| 56 | |
| 57 | // Create script & append to DOM |
| 58 | let _ctrack = window._ctrack || []; |
| 59 | |
| 60 | if (scriptInclude) { |
| 61 | let methods = ["identify", "track", "setInstance", "setAccount", "trackTime", "stopTrackTime", "debug", "setOptions"]; |
| 62 | _ctrack = methods.reduce((acc, method) => { |
| 63 | acc[method] = (...args) => { |
| 64 | _ctrack.push([method, ...args]); |
| 65 | }; |
| 66 | return acc; |
| 67 | }, _ctrack); |
| 68 | |
| 69 | window._ctrack = _ctrack; |
| 70 | |
| 71 | const script = document.createElement('script'); |
| 72 | const firstScript = document.getElementsByTagName('script')[0]; |
| 73 | script.type = 'text/javascript'; |
| 74 | script.async = true; |
| 75 | script.defer = true; |
| 76 | script.src = 'https://assets.custify.com/assets/track.min.js'; |
| 77 | firstScript.parentNode.insertBefore(script, firstScript); |
| 78 | } |
| 79 | |
| 80 | _ctrack.setAccount(accountId); |
| 81 |
nothing calls this directly
no outgoing calls
no test coverage detected