Skip to content

Commit

Permalink
add Evergage
Browse files Browse the repository at this point in the history
  • Loading branch information
ianstormtaylor committed Oct 28, 2013
1 parent e28fa94 commit 5bec987
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 241 deletions.
4 changes: 4 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.18.1 - October 28, 2013
-------------------------
* add [Evergage](http://evergage.com), by [@glajchs](https://github.com/glajchs)

0.18.0 - October 24, 2013
-------------------------
* add event emitter
Expand Down
160 changes: 141 additions & 19 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,15 +907,15 @@ exports.parse = function(url){
a.href = url;
return {
href: a.href,
host: a.host,
port: a.port,
host: a.host || location.host,
port: ('0' === a.port || '' === a.port) ? location.port : a.port,
hash: a.hash,
hostname: a.hostname,
pathname: a.pathname,
protocol: a.protocol,
hostname: a.hostname || location.hostname,
pathname: a.pathname.charAt(0) != '/' ? '/' + a.pathname : a.pathname,
protocol: !a.protocol || ':' == a.protocol ? location.protocol : a.protocol,
search: a.search,
query: a.search.slice(1)
}
};
};

/**
Expand All @@ -927,9 +927,7 @@ exports.parse = function(url){
*/

exports.isAbsolute = function(url){
if (0 == url.indexOf('//')) return true;
if (~url.indexOf('://')) return true;
return false;
return 0 == url.indexOf('//') || !!~url.indexOf('://');
};

/**
Expand All @@ -941,7 +939,7 @@ exports.isAbsolute = function(url){
*/

exports.isRelative = function(url){
return ! exports.isAbsolute(url);
return !exports.isAbsolute(url);
};

/**
Expand All @@ -954,9 +952,9 @@ exports.isRelative = function(url){

exports.isCrossDomain = function(url){
url = exports.parse(url);
return url.hostname != location.hostname
|| url.port != location.port
|| url.protocol != location.protocol;
return url.hostname !== location.hostname
|| url.port !== location.port
|| url.protocol !== location.protocol;
};
});
require.register("ianstormtaylor-callback/index.js", function(exports, require, module){
Expand Down Expand Up @@ -2226,10 +2224,10 @@ module.exports = function loadScript (options, callback) {
});
require.register("segmentio-new-date/lib/index.js", function(exports, require, module){

var is = require('is');
var isodate = require('isodate');
var milliseconds = require('./milliseconds');
var seconds = require('./seconds');
var is = require('is')
, isodate = require('isodate')
, milliseconds = require('./milliseconds')
, seconds = require('./seconds');


/**
Expand All @@ -2240,8 +2238,8 @@ var seconds = require('./seconds');
*/

module.exports = function newDate (val) {
if (is.date(val)) return val;
if (is.number(val)) return new Date(toMs(val));
if (is.date(val)) return new Date(val.getTime()); // firefox woulda floored

// date strings
if (isodate.is(val)) return isodate.parse(val);
Expand Down Expand Up @@ -2929,7 +2927,7 @@ module.exports = exports = Analytics;
*/

exports.VERSION =
Analytics.prototype.VERSION = '0.18.0';
Analytics.prototype.VERSION = '0.18.1';


/**
Expand Down Expand Up @@ -3625,6 +3623,7 @@ var integrations = [
'comscore',
'crazy-egg',
'customerio',
'evergage',
'errorception',
'foxmetrics',
'gauges',
Expand Down Expand Up @@ -5053,6 +5052,129 @@ function convertDate (date) {
return Math.floor(date.getTime() / 1000);
}
});
require.register("analytics/lib/integrations/evergage.js", function(exports, require, module){

var alias = require('alias');
var each = require('each');
var integration = require('../integration');
var load = require('load-script');


/**
* Expose `Evergage` integration.
*/

var Evergage = module.exports = integration('Evergage');


/**
* Default options.
*/

Evergage.prototype.defaults = {
// your Evergage account name as seen in accountName.evergage.com (required)
account: null,
// your Evergage dataset ID, not dataset label (required)
dataset: null
};


/**
* Initialize.
*
* @param {Object} options
* @param {Function} ready
*/

Evergage.prototype.initialize = function (options, ready) {
var account = options.account;
var dataset = options.dataset;

window._aaq = window._aaq || [];
push('setEvergageAccount', account);
push('setDataset', dataset);
push('setUseSiteConfig', true);
ready();

load('//cdn.evergage.com/beacon/' + account + '/' + dataset + '/scripts/evergage.min.js');
};


/**
* Identify.
*
* @param {String} id (optional)
* @param {Object} traits (optional)
* @param {Object} options (optional)
*/

Evergage.prototype.identify = function (id, traits, options) {
if (!id) return;
push('setUser', id);

alias(traits, {
name: 'userName',
email: 'userEmail'
});

each(traits, function (key, value) {
push('setUserField', key, value, 'page');
});
};


/**
* Group.
*
* @param {String} id
* @param {Object} properties (optional)
* @param {Object} options (optional)
*/

Evergage.prototype.group = function (id, properties, options) {
if (!id) return;
push('setCompany', id);
each(properties, function(key, value) {
push('setAccountField', key, value, 'page');
});
};


/**
* Track.
*
* @param {String} event
* @param {Object} properties (optional)
* @param {Object} options (optional)
*/

Evergage.prototype.track = function (event, properties, options) {
push('trackAction', event, properties);
};


/**
* Pageview.
*
* @param {String} url (optional)
*/

Evergage.prototype.pageview = function (url) {
window.Evergage.init(true);
};


/**
* Helper to push onto the Evergage queue.
*
* @param {Mixed} args...
*/

function push (args) {
args = [].slice.call(arguments);
window._aaq.push(args);
}
});
require.register("analytics/lib/integrations/errorception.js", function(exports, require, module){

var callback = require('callback')
Expand Down
8 changes: 4 additions & 4 deletions analytics.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "analytics",
"version": "0.18.0",
"version": "0.18.1",
"main": "analytics.js",
"dependencies": {},
"devDependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "analytics",
"repo": "segmentio/analytics.js",
"description": "The hassle-free way to integrate analytics into any web application.",
"version": "0.18.0",
"version": "0.18.1",
"keywords": [
"analytics",
"analytics.js",
Expand Down
2 changes: 1 addition & 1 deletion lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = exports = Analytics;
*/

exports.VERSION =
Analytics.prototype.VERSION = '0.18.0';
Analytics.prototype.VERSION = '0.18.1';


/**
Expand Down
73 changes: 40 additions & 33 deletions lib/integrations/evergage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

var load = require('load-script')
, integration = require('../integration')
, each = require('each');
var alias = require('alias');
var each = require('each');
var integration = require('../integration');
var load = require('load-script');


/**
Expand All @@ -19,12 +20,7 @@ Evergage.prototype.defaults = {
// your Evergage account name as seen in accountName.evergage.com (required)
account: null,
// your Evergage dataset ID, not dataset label (required)
dataset: null,
// use the minified version of the javascript
minified: true,
// the Evergage logging level to set for console logging
// http://support.evergage.com/entries/24980323-Adjusting-Console-Log-Details
loggingLevel: 'NONE'
dataset: null
};


Expand All @@ -36,17 +32,16 @@ Evergage.prototype.defaults = {
*/

Evergage.prototype.initialize = function (options, ready) {
window._aaq = window._aaq || [];
window._aaq.push(['setEvergageAccount', options.account], ['setDataset', options.dataset], ['setUseSiteConfig', true]);
if (options.loggingLevel != null) {
window._aaq.push(['setLoggingLevel', options.loggingLevel]);
}

var evergageBeaconFileName = options.minified ? 'evergage.min.js' : 'evergage.js';
load('//cdn.evergage.com/beacon/' + options.account + '/' + options.dataset + '/scripts/' + evergageBeaconFileName);
var account = options.account;
var dataset = options.dataset;

// Evergage uses a queue array, so it is ready immediatelly
window._aaq = window._aaq || [];
push('setEvergageAccount', account);
push('setDataset', dataset);
push('setUseSiteConfig', true);
ready();

load('//cdn.evergage.com/beacon/' + account + '/' + dataset + '/scripts/evergage.min.js');
};


Expand All @@ -59,16 +54,16 @@ Evergage.prototype.initialize = function (options, ready) {
*/

Evergage.prototype.identify = function (id, traits, options) {
if (!id) return; // Evergage requires an id
window._aaq.push(['setUser', id]);
each(traits, function(name, value) {
if (name == 'name') {
window._aaq.push(['setUserField', 'userName', value, 'page']);
} else if (name == 'email') {
window._aaq.push(['setUserField', 'userEmail', value, 'page']);
} else {
window._aaq.push(['setUserField', name, value, 'page']);
}
if (!id) return;
push('setUser', id);

alias(traits, {
name: 'userName',
email: 'userEmail'
});

each(traits, function (key, value) {
push('setUserField', key, value, 'page');
});
};

Expand All @@ -82,10 +77,10 @@ Evergage.prototype.identify = function (id, traits, options) {
*/

Evergage.prototype.group = function (id, properties, options) {
if (!id) return; // Evergage requires group ID
window._aaq.push(['setCompany', id]);
each(properties, function(name, value) {
window._aaq.push(['setAccountField', name, value, 'page']);
if (!id) return;
push('setCompany', id);
each(properties, function(key, value) {
push('setAccountField', key, value, 'page');
});
};

Expand All @@ -99,7 +94,7 @@ Evergage.prototype.group = function (id, properties, options) {
*/

Evergage.prototype.track = function (event, properties, options) {
window._aaq.push(['trackAction', event, properties]);
push('trackAction', event, properties);
};


Expand All @@ -112,3 +107,15 @@ Evergage.prototype.track = function (event, properties, options) {
Evergage.prototype.pageview = function (url) {
window.Evergage.init(true);
};


/**
* Helper to push onto the Evergage queue.
*
* @param {Mixed} args...
*/

function push (args) {
args = [].slice.call(arguments);
window._aaq.push(args);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "analytics.js",
"version": "0.18.0",
"version": "0.18.1",
"author": "Segment.io <[email protected]>",
"description": "The hassle-free way to integrate analytics into any web application.",
"license": "MIT",
Expand Down
Loading

0 comments on commit 5bec987

Please sign in to comment.