electron-google-analytics
Advanced tools
Comparing version 0.0.24 to 0.1.0
141
lib/index.js
@@ -49,13 +49,11 @@ 'use strict'; | ||
this.globalVersion = version; | ||
this.customParams = {}; | ||
} | ||
/** | ||
* Send a "pageview" request | ||
* Adds custom parameters to requests | ||
* if value is null, then parameter will be removed | ||
* | ||
* @param {string} url Url of the page | ||
* @param {string} title Title of the page | ||
* @param {string} hostname Document hostname | ||
* @param {string} clientID uuidV4 | ||
* | ||
* @return {Promise} | ||
* @param {string} key Parameter name | ||
* @param {string} value Parameter value | ||
*/ | ||
@@ -65,5 +63,31 @@ | ||
_createClass(Analytics, [{ | ||
key: 'set', | ||
value: function set(key, value) { | ||
if (value !== null) { | ||
this.customParams[key] = value; | ||
} else { | ||
delete this.customParams[key]; | ||
} | ||
} | ||
/** | ||
* Send a "pageview" request | ||
* | ||
* @param {string} url Url of the page | ||
* @param {string} title Title of the page | ||
* @param {string} hostname Document hostname | ||
* @param {string} clientID uuidV4 | ||
* | ||
* @return {Promise} | ||
*/ | ||
}, { | ||
key: 'pageview', | ||
value: function pageview(hostname, url, title, clientID) { | ||
var params = { dh: hostname, dp: url, dt: title }; | ||
value: function pageview(hostname, url, title, sessDuration, clientID) { | ||
var params = { | ||
dh: hostname, | ||
dp: url, | ||
dt: title, | ||
sc: sessDuration | ||
}; | ||
return this.send('pageview', params, clientID); | ||
@@ -384,2 +408,71 @@ } | ||
/** | ||
* | ||
* @param {*} hostname | ||
* @param {*} url | ||
* @param {*} title | ||
* @param {*} param3 | ||
* @param {*} clientID | ||
*/ | ||
}, { | ||
key: 'promoImp', | ||
value: function promoImp(hostname, url, title) { | ||
var _ref7 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, | ||
promoID = _ref7.promoID, | ||
promoName = _ref7.promoName, | ||
promoCrt = _ref7.promoCrt, | ||
promoPos = _ref7.promoPos; | ||
var clientID = arguments[4]; | ||
var params = { | ||
dh: hostname, | ||
dp: url, | ||
dt: title | ||
}; | ||
if (promoID) params.promo1id = promoID; | ||
if (promoName) params.promo1nm = promoName; | ||
if (promoCrt) params.promo1cr = promoCrt; | ||
if (promoPos) params.promo1ps = promoPos; | ||
return this.send('pageview', params, clientID); | ||
} | ||
/** | ||
* | ||
* @param {*} evCategory | ||
* @param {*} evAction | ||
* @param {*} param2 | ||
* @param {*} clientID | ||
*/ | ||
}, { | ||
key: 'promoCk', | ||
value: function promoCk(evCategory, evAction) { | ||
var _ref8 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
evLabel = _ref8.evLabel, | ||
promoID = _ref8.promoID, | ||
promoName = _ref8.promoName, | ||
promoCrt = _ref8.promoCrt, | ||
promoPos = _ref8.promoPos; | ||
var clientID = arguments[3]; | ||
var params = { | ||
ec: evCategory, | ||
ea: evAction, | ||
promos: 'click' | ||
}; | ||
if (evLabel) params.el = evLabel; | ||
if (promoID) params.promo1id = promoID; | ||
if (promoName) params.promo1nm = promoName; | ||
if (promoCrt) params.promo1cr = promoCrt; | ||
if (promoPos) params.promo1ps = promoPos; | ||
return this.send('event', params, clientID); | ||
} | ||
/** | ||
* Send a "item" request | ||
@@ -400,8 +493,8 @@ * @param {string} trnID Transaction ID | ||
value: function item(trnID, itemName) { | ||
var _ref7 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
itemPrice = _ref7.itemPrice, | ||
itemQty = _ref7.itemQty, | ||
itemSku = _ref7.itemSku, | ||
itemVariation = _ref7.itemVariation, | ||
currCode = _ref7.currCode; | ||
var _ref9 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
itemPrice = _ref9.itemPrice, | ||
itemQty = _ref9.itemQty, | ||
itemSku = _ref9.itemSku, | ||
itemVariation = _ref9.itemVariation, | ||
currCode = _ref9.currCode; | ||
@@ -439,9 +532,9 @@ var clientID = arguments[3]; | ||
value: function timingTrk(timingCtg, timingVar, timingTime) { | ||
var _ref8 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, | ||
timingLbl = _ref8.timingLbl, | ||
dns = _ref8.dns, | ||
pageDownTime = _ref8.pageDownTime, | ||
redirTime = _ref8.redirTime, | ||
tcpConnTime = _ref8.tcpConnTime, | ||
serverResTime = _ref8.serverResTime; | ||
var _ref10 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}, | ||
timingLbl = _ref10.timingLbl, | ||
dns = _ref10.dns, | ||
pageDownTime = _ref10.pageDownTime, | ||
redirTime = _ref10.redirTime, | ||
tcpConnTime = _ref10.tcpConnTime, | ||
serverResTime = _ref10.serverResTime; | ||
@@ -486,2 +579,6 @@ var clientID = arguments[4]; | ||
if (Object.keys(_this.customParams).length > 0) { | ||
Object.assign(formObj, _this.customParams); | ||
} | ||
var url = '' + _this.globalBaseURL + _this.globalCollectURL; | ||
@@ -488,0 +585,0 @@ if (_this.globalDebug) { |
{ | ||
"name": "electron-google-analytics", | ||
"version": "0.0.24", | ||
"version": "0.1.0", | ||
"description": "A library to implement Google Analytics in desktop apps.", | ||
@@ -28,12 +28,12 @@ "main": "lib/index.js", | ||
"chai": "^4.1.2", | ||
"cross-env": "^5.1.1", | ||
"eslint": "^4.10.0", | ||
"cross-env": "^5.1.4", | ||
"eslint": "^4.19.1", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"mocha": "^4.0.1" | ||
"eslint-plugin-import": "^2.10.0", | ||
"mocha": "^5.0.5" | ||
}, | ||
"dependencies": { | ||
"request": "^2.83.0", | ||
"uuid": "^3.1.0" | ||
"request": "^2.85.0", | ||
"uuid": "^3.2.1" | ||
} | ||
} |
@@ -41,3 +41,13 @@ ### Google Analytics - [Measurement Protocol API](https://developers.google.com/analytics/devguides/collection/protocol/v1/) | ||
``` | ||
* Set (custom params) | ||
`Analytics#set(key, value)` | ||
```javascript | ||
analytics.set('uid', 123); | ||
``` | ||
You also can remove setted parameter like this: | ||
```javascript | ||
analytics.set('uid', null); | ||
``` | ||
* Pageview | ||
@@ -197,3 +207,4 @@ | ||
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 | ||
``` | ||
```javascript | ||
const Analytics = require('electron-google-analytics'); | ||
@@ -212,2 +223,3 @@ const analytics = new Analytics.default('UA-XXXXXXXX-X'); | ||
``` | ||
#### Tests | ||
@@ -214,0 +226,0 @@ ``` |
@@ -22,5 +22,21 @@ import request from 'request'; | ||
this.globalVersion = version; | ||
this.customParams = {}; | ||
} | ||
/** | ||
* Adds custom parameters to requests | ||
* if value is null, then parameter will be removed | ||
* | ||
* @param {string} key Parameter name | ||
* @param {string} value Parameter value | ||
*/ | ||
set(key, value) { | ||
if (value !== null) { | ||
this.customParams[key] = value; | ||
} else { | ||
delete this.customParams[key]; | ||
} | ||
} | ||
/** | ||
* Send a "pageview" request | ||
@@ -36,3 +52,9 @@ * | ||
pageview(hostname, url, title, clientID) { | ||
const params = { dh: hostname, dp: url, dt: title }; | ||
// pageview(hostname, url, title, sessDuration, clientID) { | ||
const params = { | ||
dh: hostname, | ||
dp: url, | ||
dt: title | ||
// sc: sessDuration | ||
}; | ||
return this.send('pageview', params, clientID); | ||
@@ -283,2 +305,52 @@ } | ||
/** | ||
* | ||
* @param {*} hostname | ||
* @param {*} url | ||
* @param {*} title | ||
* @param {*} param3 | ||
* @param {*} clientID | ||
*/ | ||
promoImp(hostname, url, title, { | ||
promoID, promoName, promoCrt, promoPos | ||
} = {}, clientID) { | ||
const params = { | ||
dh: hostname, | ||
dp: url, | ||
dt: title | ||
}; | ||
if (promoID) params.promo1id = promoID; | ||
if (promoName) params.promo1nm = promoName; | ||
if (promoCrt) params.promo1cr = promoCrt; | ||
if (promoPos) params.promo1ps = promoPos; | ||
return this.send('pageview', params, clientID); | ||
} | ||
/** | ||
* | ||
* @param {*} evCategory | ||
* @param {*} evAction | ||
* @param {*} param2 | ||
* @param {*} clientID | ||
*/ | ||
promoCk(evCategory, evAction, { | ||
evLabel, promoID, promoName, promoCrt, promoPos | ||
} = {}, clientID) { | ||
const params = { | ||
ec: evCategory, | ||
ea: evAction, | ||
promos: 'click' | ||
}; | ||
if (evLabel) params.el = evLabel; | ||
if (promoID) params.promo1id = promoID; | ||
if (promoName) params.promo1nm = promoName; | ||
if (promoCrt) params.promo1cr = promoCrt; | ||
if (promoPos) params.promo1ps = promoPos; | ||
return this.send('event', params, clientID); | ||
} | ||
/** | ||
* Send a "item" request | ||
@@ -357,2 +429,6 @@ * @param {string} trnID Transaction ID | ||
if (Object.keys(this.customParams).length > 0) { | ||
Object.assign(formObj, this.customParams); | ||
} | ||
let url = `${this.globalBaseURL}${this.globalCollectURL}`; | ||
@@ -359,0 +435,0 @@ if (this.globalDebug) { |
Sorry, the diff of this file is not supported yet
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
193073
13
5528
230
1
Updatedrequest@^2.85.0
Updateduuid@^3.2.1