Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

piwik-tracker

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piwik-tracker - npm Package Compare versions

Comparing version 0.1.2 to 1.0.0

41

index.js

@@ -11,8 +11,10 @@ /**

var events = require('events'),
util = require('util'),
qs = require('querystring'),
agent;
const assert = require('assert');
const events = require('events');
const util = require('util');
const qs = require('querystring');
let agent;
/**

@@ -23,18 +25,10 @@ * @constructor

*/
function PiwikTracker(siteId, trackerUrl) {
function PiwikTracker (siteId, trackerUrl) {
if (!(this instanceof PiwikTracker)) { return new PiwikTracker(siteId, trackerUrl); }
events.EventEmitter.call(this);
if (!siteId || isNaN(+siteId)) {
throw new Error('siteId must be provided.');
}
assert.ok(siteId && !isNaN(siteId), 'Piwik siteId required.');
assert.ok(trackerUrl && typeof trackerUrl == 'string', 'Piwik tracker URL required, e.g. http://example.com/piwik.php')
assert.ok(trackerUrl.endsWith('piwik.php'), 'A tracker URL must end with "piwik.php"')
if (!trackerUrl || typeof trackerUrl !== 'string') {
throw new Error('A tracker URL must be provided, e.g. http://example.com/piwik.php');
}
if (trackerUrl.toString().indexOf('piwik.php') === -1) {
throw new Error('A tracker URL must contain piwik.php in the URL, e.g. http://example.com/piwik.php');
}
this.siteId = siteId;

@@ -44,3 +38,3 @@ this.trackerUrl = trackerUrl;

// Use either HTTPS or HTTP agent according to Piwik tracker URL
agent = require( /^https:/.test(trackerUrl) ? 'https' : 'http' );
agent = require( trackerUrl.startsWith('https') ? 'https' : 'http' );
}

@@ -58,4 +52,3 @@ util.inherits(PiwikTracker, events.EventEmitter);

*/
PiwikTracker.prototype.track = function track(options) {
var self = this;
PiwikTracker.prototype.track = function track (options) {
var hasErrorListeners = this.listeners('error').length;

@@ -72,15 +65,13 @@

if (!options.url) { throw new Error('URL to be tracked must be specified.'); }
assert.ok(options.url, 'URL to be tracked must be specified.');
var requestUrl = this.trackerUrl + '?' + qs.stringify(options);
var req = agent.get(requestUrl, function(res) {
var req = agent.get(requestUrl, (res) => {
// Check HTTP statuscode for 200 and 30x
if ( !/^(200|30[12478])$/.test(res.statusCode) ) {
if (hasErrorListeners) { self.emit('error', res.statusCode); }
if (hasErrorListeners) { this.emit('error', res.statusCode); }
}
});
req.on('error', function(e) {
if (hasErrorListeners) { self.emit('error', e.message); }
});
req.on('error', (err) => hasErrorListeners && this.emit('error', err.message));

@@ -87,0 +78,0 @@ req.end();

{
"name": "piwik-tracker",
"version": "0.1.2",
"version": "1.0.0",
"description": "A wrapper for the Piwik tracking HTTP API",

@@ -16,3 +16,5 @@ "keywords": [

},
"main": "./index.js",
"files": [
"index.js"
],
"repository": {

@@ -26,12 +28,12 @@ "type": "git",

"devDependencies": {
"mocha": "~1.16.2",
"sinon-chai": "~2.4.0",
"chai": "~1.8.1",
"sinon": "~1.7.3",
"nock": "~0.27.1"
"chai": "^3.5.0",
"mocha": "^2.5.3",
"nock": "^8.0.0",
"sinon": "^1.17.5",
"sinon-chai": "^2.8.0"
},
"engines": {
"node": ">=0.8.0"
"node": ">=4.2.0"
},
"license": "MIT"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc