@siteminder/canvas-analytics-js
Advanced tools
Comparing version 0.1.0 to 0.1.1
'use strict'; | ||
/** | ||
* Jsonp function | ||
* @description trigger a http request in a jsonp fashion | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
const jsonp = config => { | ||
const { url } = config; | ||
const carrierElement = document.createElement("script"); | ||
carrierElement.setAttribute("src", url); | ||
document.getElementsByTagName("head")[0].appendChild(carrierElement); | ||
carrierElement.parentNode.removeChild(carrierElement); | ||
}; | ||
var request = { | ||
/** | ||
* Get function | ||
* @description trigger a http request via GET method | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.type - set the way we send the request, "jsonp" is the only supported way for now | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
get(config) { | ||
if (config.type === "jsonp") { | ||
this.jsonp(config); | ||
} else { | ||
console.log("Unsupported request method!"); | ||
} | ||
}, | ||
/** | ||
* Get function | ||
* @description trigger a http request via GET method | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.type - set the way we send the request, "jsonp" is the only supported way for now | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
const get = config => { | ||
const { type } = config; | ||
if (type === "jsonp") { | ||
jsonp(config); | ||
} else { | ||
console.log("Unsupported request method!"); | ||
/** | ||
* Jsonp function | ||
* @description trigger a http request in a jsonp fashion | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
jsonp(config) { | ||
const { url } = config; | ||
const carrierElement = document.createElement("script"); | ||
carrierElement.setAttribute("src", url); | ||
document.getElementsByTagName("head")[0].appendChild(carrierElement); | ||
carrierElement.parentNode.removeChild(carrierElement); | ||
} | ||
}; | ||
var request = { | ||
get | ||
}; | ||
/** | ||
* Tracker Constructor | ||
* Tracker Constructor. A tracker is resposible for subscribing to | ||
* a publishable event on a target HTMLElement/window. | ||
* @param {Object} config | ||
@@ -56,25 +54,42 @@ * @param {string} config.targetElement | ||
/** Apply the tracker reporting logic to the target element */ | ||
apply() { | ||
this.targetElement[this.eventType] = this.buildEventHandler({ | ||
const handler = this.buildEventHandler({ | ||
serverUrl: this.serverUrl, | ||
hit: this.hit | ||
}); | ||
if (this.targetElement.addEventListener) { | ||
this.targetElement.addEventListener(this.eventType, handler); | ||
} else { | ||
console.log(`Failed to subscribe to a '${this.eventType | ||
}' event on '${this.targetElement && this.targetElement.tagName || this.targetElement}' element.`); | ||
} | ||
} | ||
/** Build a reporter function to be added to the target element. */ | ||
buildEventHandler(config) { | ||
const { serverUrl, hit } = config; | ||
let url = serverUrl + "/" + hit.type; | ||
let query = Object.keys(hit.data) | ||
.map(key => `${key}=${hit.data[key]}`) | ||
.join('&'); | ||
switch(hit.type) { | ||
let baseUrl = serverUrl + "/" + hit.type; | ||
let sharedQueryString = ''; | ||
if (hit.data) { | ||
sharedQueryString = Object.keys(hit.data) | ||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(hit.data[key])}`) | ||
.join('&'); | ||
} | ||
let fullQueryString = ''; | ||
switch (hit.type) { | ||
case 'pageview': | ||
if(query.length) query += '&'; | ||
query += `dp=${window.location.pathname | ||
}&dh=${window.location.host | ||
}&dt=${document.title}`; | ||
if (sharedQueryString.length > 0) { | ||
sharedQueryString += '&'; | ||
} | ||
fullQueryString += `?${sharedQueryString}dp=${encodeURIComponent(window.location.pathname)}&dh=${encodeURIComponent(window.location.host)}&dt=${encodeURIComponent(document.title)}`; | ||
break; | ||
case 'event': | ||
if (sharedQueryString.length > 0) { | ||
fullQueryString += `?${sharedQueryString}`; | ||
} | ||
break; | ||
@@ -86,4 +101,4 @@ default: | ||
return function() { | ||
request.get({ type: "jsonp", url: url + '?' + query }); | ||
return function () { | ||
request.get({ type: "jsonp", url: baseUrl + fullQueryString }); | ||
}; | ||
@@ -93,2 +108,9 @@ } | ||
const uuidv4 = () => { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); | ||
return v.toString(16); | ||
}); | ||
}; | ||
/** | ||
@@ -102,3 +124,2 @@ * Analytics Constructor | ||
constructor(config) { | ||
console.log("Canvas Analytics Javascript Plugin is loaded!"); | ||
this.config = config; | ||
@@ -108,3 +129,3 @@ } | ||
init() { | ||
const { serverUrl, trackers } = this.config; | ||
const { serverUrl, trackers, session } = this.config; | ||
trackers.forEach(item => { | ||
@@ -114,2 +135,13 @@ const target = item.target; | ||
// Inject session uuid to hit data object when it exists | ||
if (session) { | ||
if (item.hit.data) { | ||
item.hit.data[session] = this.session(); | ||
} else { | ||
item.hit.data = { | ||
[session]: this.session() | ||
}; | ||
} | ||
} | ||
let tracker = null; | ||
@@ -119,4 +151,5 @@ | ||
case "direct": | ||
if (!target.object) break; | ||
tracker = new Tracker({ | ||
targetElement: window, | ||
targetElement: target.object, | ||
eventType: target.eventType, | ||
@@ -129,15 +162,4 @@ hit, | ||
case "id": | ||
const targetElement = document.getElementById(target.matcher); | ||
tracker = new Tracker({ | ||
targetElement: targetElement, | ||
eventType: target.eventType, | ||
hit, | ||
serverUrl | ||
}); | ||
tracker.apply(); | ||
break; | ||
case "css": | ||
const targetElements = document.getElementsByClassName( | ||
case "querySelector": | ||
const targetElements = document.querySelectorAll( | ||
target.matcher | ||
@@ -149,4 +171,4 @@ ); | ||
eventType: target.eventType, | ||
hit: hit, | ||
serverUrl: serverUrl | ||
hit, | ||
serverUrl | ||
}); | ||
@@ -159,4 +181,15 @@ tracker.apply(); | ||
} | ||
session() { | ||
const currentSession = localStorage.getItem('session'); | ||
if (currentSession) { | ||
return currentSession; | ||
} else { | ||
const newSession = uuidv4(); | ||
localStorage.setItem('session', newSession); | ||
return newSession | ||
} | ||
} | ||
} | ||
module.exports = Analytics; |
@@ -1,39 +0,37 @@ | ||
/** | ||
* Jsonp function | ||
* @description trigger a http request in a jsonp fashion | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
const jsonp = config => { | ||
const { url } = config; | ||
const carrierElement = document.createElement("script"); | ||
carrierElement.setAttribute("src", url); | ||
document.getElementsByTagName("head")[0].appendChild(carrierElement); | ||
carrierElement.parentNode.removeChild(carrierElement); | ||
}; | ||
var request = { | ||
/** | ||
* Get function | ||
* @description trigger a http request via GET method | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.type - set the way we send the request, "jsonp" is the only supported way for now | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
get(config) { | ||
if (config.type === "jsonp") { | ||
this.jsonp(config); | ||
} else { | ||
console.log("Unsupported request method!"); | ||
} | ||
}, | ||
/** | ||
* Get function | ||
* @description trigger a http request via GET method | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.type - set the way we send the request, "jsonp" is the only supported way for now | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
const get = config => { | ||
const { type } = config; | ||
if (type === "jsonp") { | ||
jsonp(config); | ||
} else { | ||
console.log("Unsupported request method!"); | ||
/** | ||
* Jsonp function | ||
* @description trigger a http request in a jsonp fashion | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
jsonp(config) { | ||
const { url } = config; | ||
const carrierElement = document.createElement("script"); | ||
carrierElement.setAttribute("src", url); | ||
document.getElementsByTagName("head")[0].appendChild(carrierElement); | ||
carrierElement.parentNode.removeChild(carrierElement); | ||
} | ||
}; | ||
var request = { | ||
get | ||
}; | ||
/** | ||
* Tracker Constructor | ||
* Tracker Constructor. A tracker is resposible for subscribing to | ||
* a publishable event on a target HTMLElement/window. | ||
* @param {Object} config | ||
@@ -54,25 +52,42 @@ * @param {string} config.targetElement | ||
/** Apply the tracker reporting logic to the target element */ | ||
apply() { | ||
this.targetElement[this.eventType] = this.buildEventHandler({ | ||
const handler = this.buildEventHandler({ | ||
serverUrl: this.serverUrl, | ||
hit: this.hit | ||
}); | ||
if (this.targetElement.addEventListener) { | ||
this.targetElement.addEventListener(this.eventType, handler); | ||
} else { | ||
console.log(`Failed to subscribe to a '${this.eventType | ||
}' event on '${this.targetElement && this.targetElement.tagName || this.targetElement}' element.`); | ||
} | ||
} | ||
/** Build a reporter function to be added to the target element. */ | ||
buildEventHandler(config) { | ||
const { serverUrl, hit } = config; | ||
let url = serverUrl + "/" + hit.type; | ||
let query = Object.keys(hit.data) | ||
.map(key => `${key}=${hit.data[key]}`) | ||
.join('&'); | ||
switch(hit.type) { | ||
let baseUrl = serverUrl + "/" + hit.type; | ||
let sharedQueryString = ''; | ||
if (hit.data) { | ||
sharedQueryString = Object.keys(hit.data) | ||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(hit.data[key])}`) | ||
.join('&'); | ||
} | ||
let fullQueryString = ''; | ||
switch (hit.type) { | ||
case 'pageview': | ||
if(query.length) query += '&'; | ||
query += `dp=${window.location.pathname | ||
}&dh=${window.location.host | ||
}&dt=${document.title}`; | ||
if (sharedQueryString.length > 0) { | ||
sharedQueryString += '&'; | ||
} | ||
fullQueryString += `?${sharedQueryString}dp=${encodeURIComponent(window.location.pathname)}&dh=${encodeURIComponent(window.location.host)}&dt=${encodeURIComponent(document.title)}`; | ||
break; | ||
case 'event': | ||
if (sharedQueryString.length > 0) { | ||
fullQueryString += `?${sharedQueryString}`; | ||
} | ||
break; | ||
@@ -84,4 +99,4 @@ default: | ||
return function() { | ||
request.get({ type: "jsonp", url: url + '?' + query }); | ||
return function () { | ||
request.get({ type: "jsonp", url: baseUrl + fullQueryString }); | ||
}; | ||
@@ -91,2 +106,9 @@ } | ||
const uuidv4 = () => { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); | ||
return v.toString(16); | ||
}); | ||
}; | ||
/** | ||
@@ -100,3 +122,2 @@ * Analytics Constructor | ||
constructor(config) { | ||
console.log("Canvas Analytics Javascript Plugin is loaded!"); | ||
this.config = config; | ||
@@ -106,3 +127,3 @@ } | ||
init() { | ||
const { serverUrl, trackers } = this.config; | ||
const { serverUrl, trackers, session } = this.config; | ||
trackers.forEach(item => { | ||
@@ -112,2 +133,13 @@ const target = item.target; | ||
// Inject session uuid to hit data object when it exists | ||
if (session) { | ||
if (item.hit.data) { | ||
item.hit.data[session] = this.session(); | ||
} else { | ||
item.hit.data = { | ||
[session]: this.session() | ||
}; | ||
} | ||
} | ||
let tracker = null; | ||
@@ -117,4 +149,5 @@ | ||
case "direct": | ||
if (!target.object) break; | ||
tracker = new Tracker({ | ||
targetElement: window, | ||
targetElement: target.object, | ||
eventType: target.eventType, | ||
@@ -127,15 +160,4 @@ hit, | ||
case "id": | ||
const targetElement = document.getElementById(target.matcher); | ||
tracker = new Tracker({ | ||
targetElement: targetElement, | ||
eventType: target.eventType, | ||
hit, | ||
serverUrl | ||
}); | ||
tracker.apply(); | ||
break; | ||
case "css": | ||
const targetElements = document.getElementsByClassName( | ||
case "querySelector": | ||
const targetElements = document.querySelectorAll( | ||
target.matcher | ||
@@ -147,4 +169,4 @@ ); | ||
eventType: target.eventType, | ||
hit: hit, | ||
serverUrl: serverUrl | ||
hit, | ||
serverUrl | ||
}); | ||
@@ -157,4 +179,15 @@ tracker.apply(); | ||
} | ||
session() { | ||
const currentSession = localStorage.getItem('session'); | ||
if (currentSession) { | ||
return currentSession; | ||
} else { | ||
const newSession = uuidv4(); | ||
localStorage.setItem('session', newSession); | ||
return newSession | ||
} | ||
} | ||
} | ||
export default Analytics; |
@@ -1,1 +0,259 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Analytics=t()}(this,function(){"use strict";function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(e){"jsonp"===e.type?function(e){var t=e.url,n=document.createElement("script");n.setAttribute("src",t),document.getElementsByTagName("head")[0].appendChild(n),n.parentNode.removeChild(n)}(e):console.log("Unsupported request method!")},e=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e};function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var s=(e(l,[{key:"apply",value:function(){this.targetElement[this.eventType]=this.buildEventHandler({serverUrl:this.serverUrl,hit:this.hit})}},{key:"buildEventHandler",value:function(e){var t=e.serverUrl,n=e.hit,r=t+"/"+n.type,i=Object.keys(n.data).map(function(e){return e+"="+n.data[e]}).join("&");switch(n.type){case"pageview":i.length&&(i+="&"),i+="dp="+window.location.pathname+"&dh="+window.location.host+"&dt="+document.title;break;case"event":break;default:return void console.log("Unsupported hit type occurred")}return function(){o({type:"jsonp",url:r+"?"+i})}}}]),l);function l(e){a(this,l);var t=e.targetElement,n=e.eventType,r=e.hit,i=e.serverUrl;this.targetElement=t,this.eventType=n,this.hit=r,this.serverUrl=i}function t(e){a(this,t),console.log("Canvas Analytics Javascript Plugin is loaded!"),this.config=e}return e(t,[{key:"init",value:function(){var e=this.config,o=e.serverUrl;e.trackers.forEach(function(e){var t=e.target,n=e.hit;switch(t.selectorType){case"direct":new s({targetElement:window,eventType:t.eventType,hit:n,serverUrl:o}).apply();break;case"id":var r=document.getElementById(t.matcher);new s({targetElement:r,eventType:t.eventType,hit:n,serverUrl:o}).apply();break;case"css":for(var i=document.getElementsByClassName(t.matcher),a=0;a<i.length;a++)new s({targetElement:i[a],eventType:t.eventType,hit:n,serverUrl:o}).apply()}})}}]),t}); | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.Analytics = factory()); | ||
}(this, (function () { 'use strict'; | ||
var request = { | ||
/** | ||
* Get function | ||
* @description trigger a http request via GET method | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.type - set the way we send the request, "jsonp" is the only supported way for now | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
get: function get(config) { | ||
if (config.type === "jsonp") { | ||
this.jsonp(config); | ||
} else { | ||
console.log("Unsupported request method!"); | ||
} | ||
}, | ||
/** | ||
* Jsonp function | ||
* @description trigger a http request in a jsonp fashion | ||
* @param {Object} config - the config object for the function | ||
* @param {string} config.url - the url which the http request will hit | ||
* | ||
*/ | ||
jsonp: function jsonp(config) { | ||
var url = config.url; | ||
var carrierElement = document.createElement("script"); | ||
carrierElement.setAttribute("src", url); | ||
document.getElementsByTagName("head")[0].appendChild(carrierElement); | ||
carrierElement.parentNode.removeChild(carrierElement); | ||
} | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var createClass = function () { | ||
function defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var defineProperty = function (obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
}; | ||
/** | ||
* Tracker Constructor. A tracker is resposible for subscribing to | ||
* a publishable event on a target HTMLElement/window. | ||
* @param {Object} config | ||
* @param {string} config.targetElement | ||
* @param {string} config.eventType | ||
* @param {Object} config.hit | ||
* @param {string} config.serverUrl | ||
*/ | ||
var Tracker = function () { | ||
function Tracker(config) { | ||
classCallCheck(this, Tracker); | ||
var targetElement = config.targetElement, | ||
eventType = config.eventType, | ||
hit = config.hit, | ||
serverUrl = config.serverUrl; | ||
this.targetElement = targetElement; | ||
this.eventType = eventType; | ||
this.hit = hit; | ||
this.serverUrl = serverUrl; | ||
} | ||
/** Apply the tracker reporting logic to the target element */ | ||
createClass(Tracker, [{ | ||
key: "apply", | ||
value: function apply() { | ||
var handler = this.buildEventHandler({ | ||
serverUrl: this.serverUrl, | ||
hit: this.hit | ||
}); | ||
if (this.targetElement.addEventListener) { | ||
this.targetElement.addEventListener(this.eventType, handler); | ||
} else { | ||
console.log("Failed to subscribe to a '" + this.eventType + "' event on '" + (this.targetElement && this.targetElement.tagName || this.targetElement) + "' element."); | ||
} | ||
} | ||
/** Build a reporter function to be added to the target element. */ | ||
}, { | ||
key: "buildEventHandler", | ||
value: function buildEventHandler(config) { | ||
var serverUrl = config.serverUrl, | ||
hit = config.hit; | ||
var baseUrl = serverUrl + "/" + hit.type; | ||
var sharedQueryString = ''; | ||
if (hit.data) { | ||
sharedQueryString = Object.keys(hit.data).map(function (key) { | ||
return encodeURIComponent(key) + "=" + encodeURIComponent(hit.data[key]); | ||
}).join('&'); | ||
} | ||
var fullQueryString = ''; | ||
switch (hit.type) { | ||
case 'pageview': | ||
if (sharedQueryString.length > 0) { | ||
sharedQueryString += '&'; | ||
} | ||
fullQueryString += "?" + sharedQueryString + "dp=" + encodeURIComponent(window.location.pathname) + "&dh=" + encodeURIComponent(window.location.host) + "&dt=" + encodeURIComponent(document.title); | ||
break; | ||
case 'event': | ||
if (sharedQueryString.length > 0) { | ||
fullQueryString += "?" + sharedQueryString; | ||
} | ||
break; | ||
default: | ||
console.log("Unsupported hit type occurred"); | ||
return; | ||
} | ||
return function () { | ||
request.get({ type: "jsonp", url: baseUrl + fullQueryString }); | ||
}; | ||
} | ||
}]); | ||
return Tracker; | ||
}(); | ||
var uuidv4 = function uuidv4() { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { | ||
var r = Math.random() * 16 | 0, | ||
v = c == 'x' ? r : r & 0x3 | 0x8; | ||
return v.toString(16); | ||
}); | ||
}; | ||
/** | ||
* Analytics Constructor | ||
* @param {Object} config | ||
* @param {string} config.serverUrl - the analytics server full url | ||
* @param {Object} config.trackers - the trackers config | ||
*/ | ||
var Analytics = function () { | ||
function Analytics(config) { | ||
classCallCheck(this, Analytics); | ||
this.config = config; | ||
} | ||
createClass(Analytics, [{ | ||
key: "init", | ||
value: function init() { | ||
var _this = this; | ||
var _config = this.config, | ||
serverUrl = _config.serverUrl, | ||
trackers = _config.trackers, | ||
session = _config.session; | ||
trackers.forEach(function (item) { | ||
var target = item.target; | ||
var hit = item.hit; | ||
// Inject session uuid to hit data object when it exists | ||
if (session) { | ||
if (item.hit.data) { | ||
item.hit.data[session] = _this.session(); | ||
} else { | ||
item.hit.data = defineProperty({}, session, _this.session()); | ||
} | ||
} | ||
var tracker = null; | ||
switch (target.selectorType) { | ||
case "direct": | ||
if (!target.object) break; | ||
tracker = new Tracker({ | ||
targetElement: target.object, | ||
eventType: target.eventType, | ||
hit: hit, | ||
serverUrl: serverUrl | ||
}); | ||
tracker.apply(); | ||
break; | ||
case "querySelector": | ||
var targetElements = document.querySelectorAll(target.matcher); | ||
for (var i = 0; i < targetElements.length; i++) { | ||
tracker = new Tracker({ | ||
targetElement: targetElements[i], | ||
eventType: target.eventType, | ||
hit: hit, | ||
serverUrl: serverUrl | ||
}); | ||
tracker.apply(); | ||
} | ||
break; | ||
} | ||
}); | ||
} | ||
}, { | ||
key: "session", | ||
value: function session() { | ||
var currentSession = localStorage.getItem('session'); | ||
if (currentSession) { | ||
return currentSession; | ||
} else { | ||
var newSession = uuidv4(); | ||
localStorage.setItem('session', newSession); | ||
return newSession; | ||
} | ||
} | ||
}]); | ||
return Analytics; | ||
}(); | ||
return Analytics; | ||
}))); |
{ | ||
"name": "@siteminder/canvas-analytics-js", | ||
"version": "0.1.0", | ||
"main": "dist/analytics.cjs.js", | ||
"module": "dist/analytics.esm.js", | ||
"browser": "dist/analytics.umd.js", | ||
"publishConfig": { | ||
"access": "restricted" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-plugin-transform-object-assign": "^6.22.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babelrc-rollup": "^3.0.0", | ||
"chalk": "^2.4.1", | ||
"commitizen": "^2.9.6", | ||
"conventional-changelog": "^1.1.24", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"http-server": "^0.11.1", | ||
"rollup": "^0.58.0", | ||
"rollup-plugin-babel": "^3.0.4", | ||
"rollup-plugin-commonjs": "^9.1.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-uglify": "^4.0.0", | ||
"yorkie": "^1.0.3" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w", | ||
"dev:browser": "http-server -p 8000 -o", | ||
"test": "node test/test.js", | ||
"pretest": "npm run build", | ||
"commit": "git-cz", | ||
"release": "bash scripts/release.sh", | ||
"release:note": "node scripts/gen-release-note.js" | ||
}, | ||
"gitHooks": { | ||
"commit-msg": "node scripts/verify-commit-msg.js" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
"name": "@siteminder/canvas-analytics-js", | ||
"version": "0.1.1", | ||
"author": "SiteMinder", | ||
"publishConfig": { | ||
"access": "restricted" | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf dist/*", | ||
"compile": "rollup -c", | ||
"dev": "rollup -c -w", | ||
"dev:browser": "http-server -p 8000 -o", | ||
"test": "jest", | ||
"publish": "../../node_modules/@siteminder/overlord/shared/project/publish.sh" | ||
}, | ||
"main": "dist/analytics.cjs.js", | ||
"module": "dist/analytics.esm.js", | ||
"browser": "dist/analytics.umd.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"jest": { | ||
"testURL": "http://localhost/", | ||
"testMatch": [ | ||
"<rootDir>/src/**.spec.js" | ||
] | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-jest": "^21.0.2", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babelrc-rollup": "^3.0.0", | ||
"http-server": "^0.11.1", | ||
"jest": "^22.0.4", | ||
"rollup": "^0.58.0", | ||
"rollup-plugin-babel": "^3.0.4", | ||
"rollup-plugin-commonjs": "^9.1.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-uglify": "^4.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/siteminder-au/canvas.git" | ||
} | ||
} |
@@ -22,3 +22,4 @@ <p align="center"> | ||
const config = { | ||
serverUrl: "http://www.testdomain.com/testpath", | ||
serverUrl: "http://localhost:3040/api/v1/collect", | ||
session: 'cd3', | ||
trackers: [ | ||
@@ -28,6 +29,10 @@ { | ||
selectorType: "direct", | ||
eventType: "onload" | ||
object: window, | ||
eventType: "load" | ||
}, | ||
hit: { | ||
type: "pageview" | ||
type: "pageview", | ||
data: { | ||
cd2: "propertyId" | ||
} | ||
} | ||
@@ -38,3 +43,4 @@ }, | ||
selectorType: "direct", | ||
eventType: "onhashchange" | ||
object: window, | ||
eventType: "hashchange" | ||
}, | ||
@@ -47,5 +53,5 @@ hit: { | ||
target: { | ||
selectorType: "id", | ||
matcher: "testBtn", | ||
eventType: "onclick" | ||
selectorType: "querySelector", | ||
matcher: "#testBtn", | ||
eventType: "click" | ||
}, | ||
@@ -71,20 +77,44 @@ hit: { | ||
``` | ||
Config(Object): | ||
Config(Object) | ||
|- session(string): this field is optional. When it's enabled, a uuid string will be injected to hit.data object | ||
|- target(Object) | ||
|--- selectorType(string): "id" / "css" / "direct" | ||
|--- matcher(string): plain string not regex | ||
|--- selectorType(string): "querySelector" / "direct" | ||
|--- matcher(string): when querySelector is chosen: valid CSS selector(s) syntax | ||
|--- object(Object): when direct is chosen: window / document or other similar DOM object | ||
|--- eventType(string): all supported DOM event handlers e.g. onclick | ||
|- hit(Object): | ||
|- hit(Object) | ||
|--- type(string): "pageview", "event" | ||
|--- data(Object): ga compatible object | ||
|--- data(Object): any kind of data you want to pass to your severs like a ga compatible object | ||
``` | ||
Current custom dimensions used as data keys in Analytic API; | ||
- cd1: user-agent - Derived on the server from the client request header. | ||
- cd2: propertyId - Hotel/Site unique identifier. | ||
- cd3: sessionId - Session ID generated and stored in localStorage in the browser. | ||
- cd4: host - Property domain/host name. This is derived and passed to GA from Analytics API directly. | ||
**Methods** | ||
* `init` - init the plugin | ||
* `init()` - init the plugin | ||
**Compatibility** | ||
**Caveat** | ||
IE11+ , iOS8+ , Android 4+ and every modern Mobile or Desktop Browser. | ||
Please put the canvas-analytics-plugin ahead of its bootstrap code snippet. | ||
You are welcome to use the following pattern to load the code: | ||
``` | ||
<script src="./dist/analytics.umd.js" defer async></script> | ||
<script src="./your-bootstrap-code.js" defer async></script> | ||
in the file ./your-bootstrap-code.js | ||
... | ||
const config = {...} | ||
const analytics = new Analytics(config); | ||
analytics.init(); | ||
... | ||
``` | ||
## Setup | ||
@@ -96,20 +126,11 @@ | ||
# build | ||
npm build | ||
# compile | ||
npm run compile | ||
# git commit | ||
npm commit | ||
# run app | ||
npm dev | ||
npm dev:browser | ||
npm run dev | ||
npm run dev:browser | ||
# test | ||
npm test | ||
# generate release notes | ||
npm release:note | ||
# release new canvas version to prod | ||
npm release | ||
npm run test | ||
``` | ||
@@ -119,11 +140,6 @@ | ||
Detailed changes for each release are documented in the [release notes](https://xxx). | ||
Detailed changes for each release are documented in the [release notes](https://github.com/siteminder-au/canvas-analytics-js/releases). | ||
## Other | ||
## Commit Messages Guidelines | ||
* [Commit Messages Guidelines](COMMIT.md) | ||
## License | ||
[MIT](LICENSE). | ||
# canvas-analytics-js | ||
Detailed commit guidelines are documented in the [Commit Messages Guidelines](COMMIT_CONVENTION.md) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
22650
12
554
1
139
0
5
1