universal-analytics
Advanced tools
Comparing version 0.4.16 to 0.4.17
# Acceptable parameters | ||
------ | ||
## Protocol Version | ||
@@ -190,3 +190,3 @@ | ||
##Flash Version | ||
## Flash Version | ||
@@ -324,3 +324,3 @@ Pass as: `flashVersion` or `fl` | ||
##Transaction Revenue | ||
## Transaction Revenue | ||
@@ -327,0 +327,0 @@ Pass as: `transactionRevenue` or `tr` |
module.exports = { | ||
protocolVersion: "1", | ||
hostname: "http://www.google-analytics.com", | ||
hostname: "https://www.google-analytics.com", | ||
path: "/collect", | ||
@@ -5,0 +5,0 @@ batchPath: "/batch", |
@@ -10,2 +10,4 @@ | ||
var debug = require("debug")("universal-analytics"); | ||
module.exports = init; | ||
@@ -39,5 +41,5 @@ | ||
if (this.options.https) { | ||
if (this.options.http) { | ||
var parsedHostname = url.parse(config.hostname); | ||
config.hostname = 'https://' + parsedHostname.host; | ||
config.hostname = 'http://' + parsedHostname.host; | ||
} | ||
@@ -107,5 +109,5 @@ | ||
debug: function (debug) { | ||
this.options.debug = arguments.length === 0 ? true : debug; | ||
this._log("Logging enabled") | ||
debug: function (d) { | ||
debug.enabled = arguments.length === 0 ? true : d; | ||
debug("visitor.debug() is deprecated: set DEBUG=universal-analytics to enable logging") | ||
return this; | ||
@@ -411,3 +413,3 @@ }, | ||
var fn = fn || function () {}; | ||
self._log("Sending " + self._queue.length + " tracking call(s)"); | ||
debug("Sending %d tracking call(s)", self._queue.length); | ||
@@ -419,3 +421,3 @@ var getBody = function(params) { | ||
var onFinish = function (err) { | ||
self._log("Finished sending tracking calls") | ||
debug("Finished sending tracking calls") | ||
fn.call(self, err || null, count - 1); | ||
@@ -440,3 +442,3 @@ } | ||
self._log(count++ + ": " + JSON.stringify(params)); | ||
debug("%d: %o", count++, params); | ||
@@ -481,7 +483,7 @@ var options = Object.assign({}, self.options.requestOptions, { | ||
if (this.options.debug) { | ||
if (debug.enabled) { | ||
this._checkParameters(params); | ||
} | ||
this._log("Enqueued " + type + " (" + JSON.stringify(params) + ")"); | ||
debug("Enqueued %s (%o)", type, params); | ||
@@ -497,3 +499,3 @@ if (fn) { | ||
_handleError: function (message, fn) { | ||
this._log("Error: " + message) | ||
debug("Error: %s", message) | ||
fn && fn.call(this, new Error(message)) | ||
@@ -514,3 +516,3 @@ return this; | ||
if (id !== false) return id; | ||
if (id != null) this._log("Warning! Invalid UUID format '" + args[i] + "'"); | ||
if (id != null) debug("Warning! Invalid UUID format '%s'", args[i]); | ||
} | ||
@@ -533,3 +535,3 @@ } else { | ||
} | ||
this._log("Warning! Unsupported tracking parameter " + param + " (" + params[param] + ")"); | ||
debug("Warning! Unsupported tracking parameter %s (%s)", param, params[param]); | ||
} | ||
@@ -559,8 +561,2 @@ }, | ||
_log: function (message) { | ||
this.options.debug && console.log("[universal-analytics] " + message); | ||
}, | ||
_withContext: function (context) { | ||
@@ -567,0 +563,0 @@ var visitor = new Visitor(this.tid, this.cid, this.options, context, this._persistentParams); |
{ | ||
"name": "universal-analytics", | ||
"version": "0.4.16", | ||
"version": "0.4.17", | ||
"description": "A node module for Google's Universal Analytics tracking", | ||
@@ -20,3 +20,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"request": "2.x", | ||
"debug": "^3.0.0", | ||
"request": "2.86.0", | ||
"uuid": "^3.0.0" | ||
@@ -23,0 +24,0 @@ }, |
@@ -49,3 +49,3 @@ universal-analytics | ||
This will create a `universal-analytics` Visitor instance that you can use and keep around to track a specific user. Since no user UUID was specified in the constructor's arguments, a random UUID is generated. In case you have a user UUID at hand, you can use that to create the visitor: | ||
This will create a `universal-analytics` Visitor instance that you can use and keep around to track a specific client (Not to be confused with the Google Analytics User ID, see [Setting persistent parameters](#setting-persistent-parameters) for more information on that). Since no client ID was specified in the constructor's arguments, a random UUID is generated. In case you have a client ID at hand, you can use that to create the visitor: | ||
@@ -56,11 +56,11 @@ ```javascript | ||
Starting with Universal Analytics, a UUID v4 is the preferred user ID format. It is therefor necessary to provide a UUID of such type to `universal-analytics`. However you can force custom user ID, passing `strictCidFormat: false` in the options: | ||
Starting with Universal Analytics, a UUID v4 is the preferred client ID format. It is therefor necessary to provide a UUID of such type to `universal-analytics`. However you can force custom client ID, passing `strictCidFormat: false` in the options: | ||
```javascript | ||
var visitor = ua('UA-XXXX-XX', 'CUSTOM_USERID_1', {strictCidFormat: false}); | ||
var visitor = ua('UA-XXXX-XX', 'CUSTOM_CLIENTID_1', {strictCidFormat: false}); | ||
``` | ||
If you want to use Google Analytics in https protocol, just include it in the options `https: true`, by default will use http: | ||
If you want to use Google Analytics in http protocol, just include it in the options `http: true`, by default will use https: | ||
```javascript | ||
var visitor = ua('UA-XXXX-XX', {https: true}); | ||
var visitor = ua('UA-XXXX-XX', {http: true}); | ||
``` | ||
@@ -510,3 +510,3 @@ | ||
```javascript | ||
visitor.set("uid", "123456789") | ||
visitor.set("uid", "123456789"); | ||
``` | ||
@@ -516,9 +516,8 @@ | ||
For custom dimensions, you will not pass `dimension#` rather `cd#`: | ||
```javascript | ||
visitor.set("cd[1-20]", "123456789"); // [1-20] will be the dimension number | ||
``` | ||
# Session-based identification | ||
@@ -547,8 +546,7 @@ | ||
`universal-analytics` can be instructed to output information during tracking by enabling the debug mode: | ||
`universal-analytics` is using the [`debug`](https://www.npmjs.com/package/debug) library. It can be instructed to output information during tracking by setting the `DEBUG` environment variable: | ||
```javascript | ||
var visitor = ua("UA-XXXX-XX").debug() | ||
// … and so forth. | ||
``` | ||
DEBUG=universal-analytics | ||
``` | ||
@@ -555,0 +553,0 @@ |
@@ -87,7 +87,7 @@ | ||
}; | ||
var next = sinon.spy(uuid, 'v4') | ||
var visitor = ua(options); | ||
next.calledOnce.should.equal(true, "next() should've been called once") | ||
@@ -107,7 +107,7 @@ var generatedCid = next.returnValues[0] | ||
}; | ||
var next = sinon.spy(uuid, 'v4') | ||
var visitor = ua(options); | ||
next.called.should.equal(false, "next() should't be called") | ||
@@ -121,5 +121,5 @@ uuid.v4.restore() | ||
describe("params", function () { | ||
var visitor; | ||
before(function () { | ||
@@ -130,3 +130,3 @@ var tid = "UA-XXXXX-XX"; | ||
}); | ||
it('should not translate params', function(){ | ||
@@ -139,7 +139,7 @@ var params = { | ||
}; | ||
visitor._translateParams(params).should.eql(params); | ||
visitor._translateParams(params).should.eql(params); | ||
}) | ||
it('should match all parameters and each should be in the list of accepted', function(){ | ||
it('should match all parameters and each should be in the list of accepted', function(){ | ||
var res = visitor._translateParams(config.parametersMap); | ||
@@ -151,51 +151,7 @@ for (var i in res) { | ||
} | ||
} | ||
} | ||
}) | ||
}); | ||
describe("#debug", function () { | ||
var log; | ||
before(function () { | ||
log = sinon.stub(ua.Visitor.prototype, "_log") | ||
}); | ||
after(function () { | ||
log.restore(); | ||
}); | ||
it("should enable debugging when invoked without arguments", function () { | ||
var visitor = ua().debug() | ||
visitor.options.debug.should.equal(true); | ||
visitor.debug().should.equal(visitor, "should return itself") | ||
visitor.options.debug.should.equal(true, "A second #debug call should leave debugging enabled"); | ||
}); | ||
it("should toggle debugging when invoked with a boolean arguments", function () { | ||
var visitor = ua().debug(true) | ||
visitor.options.debug.should.equal(true); | ||
visitor.debug(false).should.equal(visitor, "should return itself") | ||
visitor.options.debug.should.equal(false); | ||
}); | ||
}); | ||
}); | ||
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
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
165374
3
2625
630
+ Addeddebug@^3.0.0
+ Addedajv@5.5.2(transitive)
+ Addedboom@4.3.15.3.3(transitive)
+ Addedco@4.6.0(transitive)
+ Addedcryptiles@3.2.1(transitive)
+ Addeddebug@3.2.7(transitive)
+ Addedfast-deep-equal@1.1.0(transitive)
+ Addedhar-validator@5.0.3(transitive)
+ Addedhawk@6.0.2(transitive)
+ Addedhoek@4.3.1(transitive)
+ Addedjson-schema-traverse@0.3.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedrequest@2.86.0(transitive)
+ Addedsntp@2.1.0(transitive)
+ Addedtough-cookie@2.3.4(transitive)
- Removedajv@6.12.6(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedpsl@1.10.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedrequest@2.88.2(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removeduri-js@4.4.1(transitive)
Updatedrequest@2.86.0