electron-google-analytics
Advanced tools
Comparing version 0.0.17 to 0.0.18
124
lib/index.js
@@ -37,17 +37,14 @@ 'use strict'; | ||
// Debug | ||
this._debug = debug; | ||
this.globalDebug = debug; | ||
// User-agent | ||
this._userAgent = userAgent; | ||
this.globalUserAgent = userAgent; | ||
// Links | ||
this._baseURL = 'https://www.google-analytics.com'; | ||
this._debugURL = '/debug'; | ||
this._collectURL = '/collect'; | ||
this._batchURL = '/batch'; | ||
this.globalBaseURL = 'https://www.google-analytics.com'; | ||
this.globalDebugURL = '/debug'; | ||
this.globalCollectURL = '/collect'; | ||
this.globalBatchURL = '/batch'; | ||
// Google generated ID | ||
this._trackingID = trackingID; | ||
this.globalTrackingID = trackingID; | ||
// Google API version | ||
this._version = version; | ||
this.globalVersion = version; | ||
} | ||
@@ -96,4 +93,4 @@ | ||
if (evLabel) params['el'] = evLabel; | ||
if (evValue) params['ev'] = evValue; | ||
if (evLabel) params.el = evLabel; | ||
if (evValue) params.ev = evValue; | ||
@@ -158,7 +155,7 @@ return this.send('event', params, clientID); | ||
if (trnAffil) params['ta'] = trnAffil; | ||
if (trnRev) params['tr'] = trnRev; | ||
if (trnShip) params['ts'] = trnShip; | ||
if (trnTax) params['tt'] = trnTax; | ||
if (currCode) params['cu'] = currCode; | ||
if (trnAffil) params.ta = trnAffil; | ||
if (trnRev) params.tr = trnRev; | ||
if (trnShip) params.ts = trnShip; | ||
if (trnTax) params.tt = trnTax; | ||
if (currCode) params.cu = currCode; | ||
@@ -182,7 +179,3 @@ return this.send('transaction', params, clientID); | ||
value: function social(socialAction, socialNetwork, socialTarget, clientID) { | ||
var params = { | ||
sa: socialAction, | ||
sn: socialNetwork, | ||
st: socialTarget | ||
}; | ||
var params = { sa: socialAction, sn: socialNetwork, st: socialTarget }; | ||
@@ -266,12 +259,9 @@ return this.send('social', params, clientID); | ||
var params = { | ||
ti: trnID, | ||
in: itemName | ||
}; | ||
var params = { ti: trnID, in: itemName }; | ||
if (itemPrice) params['ip'] = itemPrice; | ||
if (itemQty) params['iq'] = itemQty; | ||
if (itemSku) params['ic'] = itemSku; | ||
if (itemVariation) params['iv'] = itemVariation; | ||
if (currCode) params['cu'] = currCode; | ||
if (itemPrice) params.ip = itemPrice; | ||
if (itemQty) params.iq = itemQty; | ||
if (itemSku) params.ic = itemSku; | ||
if (itemVariation) params.iv = itemVariation; | ||
if (currCode) params.cu = currCode; | ||
@@ -309,14 +299,10 @@ return this.send('item', params, clientID); | ||
var params = { | ||
utc: timingCtg, | ||
utv: timingVar, | ||
utt: timingTime | ||
}; | ||
var params = { utc: timingCtg, utv: timingVar, utt: timingTime }; | ||
if (timingLbl) params['url'] = timingLbl; | ||
if (dns) params['dns'] = dns; | ||
if (pageDownTime) params['pdt'] = pageDownTime; | ||
if (redirTime) params['rrt'] = redirTime; | ||
if (tcpConnTime) params['tcp'] = tcpConnTime; | ||
if (serverResTime) params['srt'] = serverResTime; | ||
if (timingLbl) params.url = timingLbl; | ||
if (dns) params.dns = dns; | ||
if (pageDownTime) params.pdt = pageDownTime; | ||
if (redirTime) params.rrt = redirTime; | ||
if (tcpConnTime) params.tcp = tcpConnTime; | ||
if (serverResTime) params.srt = serverResTime; | ||
@@ -343,4 +329,4 @@ return this.send('timing', params, clientID); | ||
var formObj = { | ||
v: _this._version, | ||
tid: _this._trackingID, | ||
v: _this.globalVersion, | ||
tid: _this.globalTrackingID, | ||
cid: clientID || (0, _v2.default)(), | ||
@@ -351,10 +337,10 @@ t: hitType | ||
var url = '' + _this._baseURL + _this._collectURL; | ||
if (_this._debug) { | ||
url = '' + _this._baseURL + _this._debugURL + _this._collectURL; | ||
var url = '' + _this.globalBaseURL + _this.globalCollectURL; | ||
if (_this.globalDebug) { | ||
url = '' + _this.globalBaseURL + _this.globalDebugURL + _this.globalCollectURL; | ||
} | ||
var reqObj = { url: url, form: formObj }; | ||
if (_this._userAgent !== '') { | ||
reqObj['headers'] = { 'User-Agent': _this._userAgent }; | ||
if (_this.globalUserAgent !== '') { | ||
reqObj.headers = { 'User-Agent': _this.globalUserAgent }; | ||
} | ||
@@ -371,3 +357,3 @@ | ||
if (httpResponse.statusCode === 200) { | ||
if (_this._debug) { | ||
if (_this.globalDebug) { | ||
if (bodyJson.hitParsingResult[0].valid) { | ||
@@ -383,3 +369,5 @@ return resolve({ clientID: formObj.cid }); | ||
if (httpResponse.headers['content-type'] !== 'image/gif') return reject(bodyJson); | ||
if (httpResponse.headers['content-type'] !== 'image/gif') { | ||
return reject(bodyJson); | ||
} | ||
@@ -393,6 +381,6 @@ return reject(body); | ||
get: function get() { | ||
return this._debug; | ||
return this.globalDebug; | ||
}, | ||
set: function set(value) { | ||
this._debug = value; | ||
this.globalDebug = value; | ||
} | ||
@@ -402,6 +390,6 @@ }, { | ||
get: function get() { | ||
return this._userAgent; | ||
return this.globalUserAgent; | ||
}, | ||
set: function set(value) { | ||
this._userAgent = value; | ||
this.globalUserAgent = value; | ||
} | ||
@@ -411,6 +399,6 @@ }, { | ||
get: function get() { | ||
return this._baseURL; | ||
return this.globalBaseURL; | ||
}, | ||
set: function set(value) { | ||
this._baseURL = value; | ||
this.globalBaseURL = value; | ||
} | ||
@@ -420,6 +408,6 @@ }, { | ||
get: function get() { | ||
return this._debugURL; | ||
return this.globalDebugURL; | ||
}, | ||
set: function set(value) { | ||
this._debugURL = value; | ||
this.globalDebugURL = value; | ||
} | ||
@@ -429,6 +417,6 @@ }, { | ||
get: function get() { | ||
return this._collectURL; | ||
return this.globalCollectURL; | ||
}, | ||
set: function set(value) { | ||
this._collectURL = value; | ||
this.globalCollectURL = value; | ||
} | ||
@@ -438,6 +426,6 @@ }, { | ||
get: function get() { | ||
return this._batchURL; | ||
return this.globalBatchURL; | ||
}, | ||
set: function set(value) { | ||
this._batchURL = value; | ||
this.globalBatchURL = value; | ||
} | ||
@@ -447,6 +435,6 @@ }, { | ||
get: function get() { | ||
return this._trackingID; | ||
return this.globalTrackingID; | ||
}, | ||
set: function set(value) { | ||
this._trackingID = value; | ||
this.globalTrackingID = value; | ||
} | ||
@@ -456,6 +444,6 @@ }, { | ||
get: function get() { | ||
return this._version; | ||
return this.globalVersion; | ||
}, | ||
set: function set(value) { | ||
this._version = value; | ||
this.globalVersion = value; | ||
} | ||
@@ -462,0 +450,0 @@ }]); |
{ | ||
"name": "electron-google-analytics", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "A library to implement Google Analytics in desktop apps.", | ||
@@ -24,13 +24,16 @@ "main": "lib/index.js", | ||
"babel-core": "^6.26.0", | ||
"babel-preset-env": "^1.6.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-register": "^6.26.0", | ||
"chai": "^4.1.2", | ||
"cross-env": "^5.0.5", | ||
"mocha": "^3.5.0" | ||
"cross-env": "^5.1.1", | ||
"eslint": "^4.10.0", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"mocha": "^4.0.1" | ||
}, | ||
"dependencies": { | ||
"request": "^2.81.0", | ||
"request": "^2.83.0", | ||
"uuid": "^3.1.0" | ||
} | ||
} |
@@ -148,3 +148,18 @@ ### Google Analytics - [Measurement Protocol API](https://developers.google.com/analytics/devguides/collection/protocol/v1/) | ||
``` | ||
#### es5 usage | ||
If you are not using tools like babel to use es6 with your application, you'll have to modify your code slightly. Below is an example of a test screen view that you can use out of the box with node.js | ||
``` | ||
const Analytics = require('electron-google-analytics'); | ||
const analytics = new Analytics.default('UA-XXXXXXXX-X'); | ||
function test(){ | ||
return analytics.screen('test', '1.0.0', 'com.app.test', 'com.app.installer', 'Test') | ||
.then((response) => { | ||
return response; | ||
}).catch((err) => { | ||
return err; | ||
}); | ||
} | ||
test(); | ||
``` | ||
#### Tests | ||
@@ -151,0 +166,0 @@ ``` |
134
src/index.js
@@ -10,81 +10,78 @@ import request from 'request'; | ||
// Debug | ||
this._debug = debug; | ||
this.globalDebug = debug; | ||
// User-agent | ||
this._userAgent = userAgent; | ||
this.globalUserAgent = userAgent; | ||
// Links | ||
this._baseURL = 'https://www.google-analytics.com'; | ||
this._debugURL = '/debug'; | ||
this._collectURL = '/collect'; | ||
this._batchURL = '/batch'; | ||
this.globalBaseURL = 'https://www.google-analytics.com'; | ||
this.globalDebugURL = '/debug'; | ||
this.globalCollectURL = '/collect'; | ||
this.globalBatchURL = '/batch'; | ||
// Google generated ID | ||
this._trackingID = trackingID; | ||
this.globalTrackingID = trackingID; | ||
// Google API version | ||
this._version = version; | ||
this.globalVersion = version; | ||
} | ||
get debug() { | ||
return this._debug; | ||
return this.globalDebug; | ||
} | ||
set debug(value) { | ||
this._debug = value; | ||
this.globalDebug = value; | ||
} | ||
get userAgent() { | ||
return this._userAgent; | ||
return this.globalUserAgent; | ||
} | ||
set userAgent(value) { | ||
this._userAgent = value; | ||
this.globalUserAgent = value; | ||
} | ||
get baseURL() { | ||
return this._baseURL; | ||
return this.globalBaseURL; | ||
} | ||
set baseURL(value) { | ||
this._baseURL = value; | ||
this.globalBaseURL = value; | ||
} | ||
get debugURL() { | ||
return this._debugURL; | ||
return this.globalDebugURL; | ||
} | ||
set debugURL(value) { | ||
this._debugURL = value; | ||
this.globalDebugURL = value; | ||
} | ||
get collectURL() { | ||
return this._collectURL; | ||
return this.globalCollectURL; | ||
} | ||
set collectURL(value) { | ||
this._collectURL = value; | ||
this.globalCollectURL = value; | ||
} | ||
get batchURL() { | ||
return this._batchURL; | ||
return this.globalBatchURL; | ||
} | ||
set batchURL(value) { | ||
this._batchURL = value; | ||
this.globalBatchURL = value; | ||
} | ||
get trackingID() { | ||
return this._trackingID; | ||
return this.globalTrackingID; | ||
} | ||
set trackingID(value) { | ||
this._trackingID = value; | ||
this.globalTrackingID = value; | ||
} | ||
get version() { | ||
return this._version; | ||
return this.globalVersion; | ||
} | ||
set version(value) { | ||
this._version = value; | ||
this.globalVersion = value; | ||
} | ||
@@ -121,4 +118,4 @@ | ||
if (evLabel) params['el'] = evLabel; | ||
if (evValue) params['ev'] = evValue; | ||
if (evLabel) params.el = evLabel; | ||
if (evValue) params.ev = evValue; | ||
@@ -165,10 +162,12 @@ return this.send('event', params, clientID); | ||
*/ | ||
transaction(trnID, { trnAffil, trnRev, trnShip, trnTax, currCode } = {}, clientID) { | ||
transaction(trnID, { | ||
trnAffil, trnRev, trnShip, trnTax, currCode | ||
} = {}, clientID) { | ||
let params = { ti: trnID }; | ||
if (trnAffil) params['ta'] = trnAffil; | ||
if (trnRev) params['tr'] = trnRev; | ||
if (trnShip) params['ts'] = trnShip; | ||
if (trnTax) params['tt'] = trnTax; | ||
if (currCode) params['cu'] = currCode; | ||
if (trnAffil) params.ta = trnAffil; | ||
if (trnRev) params.tr = trnRev; | ||
if (trnShip) params.ts = trnShip; | ||
if (trnTax) params.tt = trnTax; | ||
if (currCode) params.cu = currCode; | ||
@@ -189,7 +188,3 @@ return this.send('transaction', params, clientID); | ||
social(socialAction, socialNetwork, socialTarget, clientID) { | ||
const params = { | ||
sa: socialAction, | ||
sn: socialNetwork, | ||
st: socialTarget | ||
}; | ||
const params = { sa: socialAction, sn: socialNetwork, st: socialTarget }; | ||
@@ -249,13 +244,12 @@ return this.send('social', params, clientID); | ||
*/ | ||
item(trnID, itemName, { itemPrice, itemQty, itemSku, itemVariation, currCode } = {}, clientID) { | ||
let params = { | ||
ti: trnID, | ||
in: itemName | ||
}; | ||
item(trnID, itemName, { | ||
itemPrice, itemQty, itemSku, itemVariation, currCode | ||
} = {}, clientID) { | ||
let params = { ti: trnID, in: itemName }; | ||
if (itemPrice) params['ip'] = itemPrice; | ||
if (itemQty) params['iq'] = itemQty; | ||
if (itemSku) params['ic'] = itemSku; | ||
if (itemVariation) params['iv'] = itemVariation; | ||
if (currCode) params['cu'] = currCode; | ||
if (itemPrice) params.ip = itemPrice; | ||
if (itemQty) params.iq = itemQty; | ||
if (itemSku) params.ic = itemSku; | ||
if (itemVariation) params.iv = itemVariation; | ||
if (currCode) params.cu = currCode; | ||
@@ -282,14 +276,10 @@ return this.send('item', params, clientID); | ||
} = {}, clientID) { | ||
let params = { | ||
utc: timingCtg, | ||
utv: timingVar, | ||
utt: timingTime | ||
}; | ||
let params = { utc: timingCtg, utv: timingVar, utt: timingTime }; | ||
if (timingLbl) params['url'] = timingLbl; | ||
if (dns) params['dns'] = dns; | ||
if (pageDownTime) params['pdt'] = pageDownTime; | ||
if (redirTime) params['rrt'] = redirTime; | ||
if (tcpConnTime) params['tcp'] = tcpConnTime; | ||
if (serverResTime) params['srt'] = serverResTime; | ||
if (timingLbl) params.url = timingLbl; | ||
if (dns) params.dns = dns; | ||
if (pageDownTime) params.pdt = pageDownTime; | ||
if (redirTime) params.rrt = redirTime; | ||
if (tcpConnTime) params.tcp = tcpConnTime; | ||
if (serverResTime) params.srt = serverResTime; | ||
@@ -311,4 +301,4 @@ return this.send('timing', params, clientID); | ||
let formObj = { | ||
v: this._version, | ||
tid: this._trackingID, | ||
v: this.globalVersion, | ||
tid: this.globalTrackingID, | ||
cid: clientID || uuidV4(), | ||
@@ -319,10 +309,10 @@ t: hitType | ||
let url = `${this._baseURL}${this._collectURL}`; | ||
if (this._debug) { | ||
url = `${this._baseURL}${this._debugURL}${this._collectURL}`; | ||
let url = `${this.globalBaseURL}${this.globalCollectURL}`; | ||
if (this.globalDebug) { | ||
url = `${this.globalBaseURL}${this.globalDebugURL}${this.globalCollectURL}`; | ||
} | ||
let reqObj = { url: url, form: formObj }; | ||
if (this._userAgent !== '') { | ||
reqObj['headers'] = { 'User-Agent': this._userAgent }; | ||
let reqObj = { url, form: formObj }; | ||
if (this.globalUserAgent !== '') { | ||
reqObj.headers = { 'User-Agent': this.globalUserAgent }; | ||
} | ||
@@ -333,3 +323,2 @@ | ||
let bodyJson = {}; | ||
@@ -341,3 +330,3 @@ if (body && (httpResponse.headers['content-type'] !== 'image/gif')) { | ||
if (httpResponse.statusCode === 200) { | ||
if (this._debug) { | ||
if (this.globalDebug) { | ||
if (bodyJson.hitParsingResult[0].valid) { | ||
@@ -353,4 +342,5 @@ return resolve({ clientID: formObj.cid }); | ||
if (httpResponse.headers['content-type'] !== 'image/gif') | ||
if (httpResponse.headers['content-type'] !== 'image/gif') { | ||
return reject(bodyJson); | ||
} | ||
@@ -357,0 +347,0 @@ return reject(body); |
@@ -8,3 +8,2 @@ import chai from 'chai'; | ||
describe('Analytics', function() { | ||
if (trackingID) { | ||
@@ -15,7 +14,7 @@ it('should send a pageview request', function() { | ||
return analytics.pageview('http://example.com', '/test', 'Test') | ||
.then((response) => { | ||
return expect(response).to.have.property('clientID'); | ||
}).catch((err) => { | ||
return expect(err).to.be.empty; | ||
}); | ||
.then((response) => { | ||
return expect(response).to.have.property('clientID'); | ||
}).catch((err) => { | ||
return expect(err).to.be.empty; | ||
}); | ||
}); | ||
@@ -37,7 +36,7 @@ | ||
return analytics.screen('test', '1.0.0', 'com.app.test', 'com.app.installer', 'Test') | ||
.then((response) => { | ||
return expect(response).to.have.property('clientID'); | ||
}).catch((err) => { | ||
return expect(err).to.be.empty; | ||
}); | ||
.then((response) => { | ||
return expect(response).to.have.property('clientID'); | ||
}).catch((err) => { | ||
return expect(err).to.be.empty; | ||
}); | ||
}); | ||
@@ -109,7 +108,7 @@ | ||
return analytics.send('social', { sa: 'social', sn: 'facebook', st: 'home' }) | ||
.then((response) => { | ||
return expect(response).to.have.property('clientID'); | ||
}).catch((err) => { | ||
return expect(err).to.be.empty; | ||
}); | ||
.then((response) => { | ||
return expect(response).to.have.property('clientID'); | ||
}).catch((err) => { | ||
return expect(err).to.be.empty; | ||
}); | ||
}); | ||
@@ -123,7 +122,7 @@ } | ||
return analytics.pageview('http://example.com', 'test', 'test') | ||
.then((response) => { | ||
return expect(response).to.be.empty; | ||
}).catch((err) => { | ||
return expect(err).to.not.be.empty; | ||
}); | ||
.then((response) => { | ||
return expect(response).to.be.empty; | ||
}).catch((err) => { | ||
return expect(err).to.not.be.empty; | ||
}); | ||
}); | ||
@@ -145,7 +144,7 @@ | ||
return analytics.screen('test', '1.0.0', 'com.app.test', 'com.app.installer', 'Test') | ||
.then((response) => { | ||
return expect(response).to.be.empty; | ||
}).catch((err) => { | ||
return expect(err).to.not.be.empty; | ||
}); | ||
.then((response) => { | ||
return expect(response).to.be.empty; | ||
}).catch((err) => { | ||
return expect(err).to.not.be.empty; | ||
}); | ||
}); | ||
@@ -217,8 +216,8 @@ | ||
return analytics.send('social', { sa: 'social', sn: 'facebook', st: 'home' }) | ||
.then((response) => { | ||
return expect(response).to.be.empty; | ||
}).catch((err) => { | ||
return expect(err).to.not.be.empty; | ||
}); | ||
.then((response) => { | ||
return expect(response).to.be.empty; | ||
}).catch((err) => { | ||
return expect(err).to.not.be.empty; | ||
}); | ||
}); | ||
}); |
35769
170
11
840
Updatedrequest@^2.83.0