Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
* add `name` and `category` defaults to `page` method calls
* update `analytics.js-integrations` to `0.2.7`
  • Loading branch information
ianstormtaylor committed Nov 20, 2013
1 parent 3347ec8 commit 6f675b2
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 50 deletions.
5 changes: 5 additions & 0 deletions History.md
@@ -1,3 +1,8 @@
1.1.0 - November 20, 2013
-------------------------
* add `name` and `category` defaults to `page` method calls
* update `analytics.js-integrations` to `0.2.7`

1.0.9 - November 15, 2013
-------------------------
* update `analytics.js-integrations` to `0.2.6`
Expand Down
80 changes: 58 additions & 22 deletions analytics.js
Expand Up @@ -898,15 +898,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) ? port(a.protocol) : 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 @@ -918,9 +918,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 @@ -932,7 +930,7 @@ exports.isAbsolute = function(url){
*/

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

/**
Expand All @@ -945,10 +943,29 @@ 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;
};

/**
* Return default port for `protocol`.
*
* @param {String} protocol
* @return {String}
* @api private
*/
function port (protocol){
switch (protocol) {
case 'http:':
return 80;
case 'https:':
return 443;
default:
return location.port;
}
}

});
require.register("component-bind/index.js", function(exports, require, module){

Expand Down Expand Up @@ -3638,10 +3655,16 @@ Evergage.prototype.load = function (callback) {
*/

Evergage.prototype.page = function (category, name, properties, options) {
if (name) push('namePage', name);

properties = properties || {};
each(properties, function(key, value) {
push('setCustomField', key, value, 'page');
});

window.Evergage.init(true);
};


/**
* Trait aliases.
*/
Expand Down Expand Up @@ -8513,11 +8536,19 @@ exports.is = function (string, strict) {
});
require.register("segmentio-isodate-traverse/index.js", function(exports, require, module){

var clone = require('clone')
, each = require('each')
, is = require('is')
, isodate = require('isodate');
var is = require('is');
var isodate = require('isodate');

var clone;
var each;

try {
clone = require('clone');
each = require('each');
} catch (err) {
clone = require('clone-component');
each = require('each-component');
}

/**
* Expose `traverse`.
Expand Down Expand Up @@ -9513,7 +9544,7 @@ var analytics = module.exports = exports = new Analytics();
* Expose `VERSION`.
*/

exports.VERSION = '1.0.9';
exports.VERSION = '1.1.0';


/**
Expand Down Expand Up @@ -9869,13 +9900,18 @@ Analytics.prototype.page = function (category, name, properties, options, fn) {
if (is.object(category)) options = properties, properties = name, name = category = null;
if (is.string(category) && !is.string(name)) name = category, category = null;

properties = clone(properties) || {};
defaults(properties, {
var defs = {
path: canonicalPath(),
referrer: document.referrer,
title: document.title,
url: location.href
});
};

if (name) defs.name = name;
if (category) defs.category = category;

properties = clone(properties) || {};
defaults(properties, defs);

this._invoke('page', category, name, properties, options);
this._callback(fn);
Expand Down
10 changes: 5 additions & 5 deletions analytics.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "analytics",
"version": "1.0.9",
"version": "1.1.0",
"main": "analytics.js",
"dependencies": {},
"devDependencies": {}
Expand Down
4 changes: 2 additions & 2 deletions component.json
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": "1.0.9",
"version": "1.1.0",
"keywords": [
"analytics",
"analytics.js",
Expand All @@ -24,7 +24,7 @@
"ianstormtaylor/is": "0.1.0",
"segmentio/after": "0.0.1",
"segmentio/analytics.js-integration": "0.1.4",
"segmentio/analytics.js-integrations": "0.2.6",
"segmentio/analytics.js-integrations": "0.2.7",
"segmentio/canonical": "0.0.1",
"segmentio/extend": "0.0.1",
"segmentio/is-email": "0.1.1",
Expand Down
11 changes: 8 additions & 3 deletions lib/analytics.js
Expand Up @@ -342,13 +342,18 @@ Analytics.prototype.page = function (category, name, properties, options, fn) {
if (is.object(category)) options = properties, properties = name, name = category = null;
if (is.string(category) && !is.string(name)) name = category, category = null;

properties = clone(properties) || {};
defaults(properties, {
var defs = {
path: canonicalPath(),
referrer: document.referrer,
title: document.title,
url: location.href
});
};

if (name) defs.name = name;
if (category) defs.category = category;

properties = clone(properties) || {};
defaults(properties, defs);

this._invoke('page', category, name, properties, options);
this._callback(fn);
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -21,7 +21,7 @@ var analytics = module.exports = exports = new Analytics();
* Expose `VERSION`.
*/

exports.VERSION = '1.0.9';
exports.VERSION = '1.1.0';


/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "analytics.js",
"author": "Segment.io <friends@segment.io>",
"version": "1.0.9",
"version": "1.1.0",
"license": "MIT",
"description": "The hassle-free way to integrate analytics into any web application.",
"keywords": ["analytics", "analytics.js", "segment", "segment.io"],
Expand Down
44 changes: 29 additions & 15 deletions test/analytics.js
Expand Up @@ -294,14 +294,15 @@ describe('Analytics', function () {
});

describe('#page', function () {
var properties = {
path: window.location.pathname,
referrer: document.referrer,
title: document.title,
url: window.location.href
};
var defaults;

beforeEach(function () {
defaults = {
path: window.location.pathname,
referrer: document.referrer,
title: document.title,
url: window.location.href
};
sinon.spy(analytics, '_invoke');
});

Expand All @@ -311,46 +312,57 @@ describe('Analytics', function () {
});

it('should back properties with defaults', function () {
defaults.category = 'category';
defaults.name = 'name';
analytics.page('category', 'name', {});
assert(analytics._invoke.calledWith('page', 'category', 'name', properties));
assert(analytics._invoke.calledWith('page', 'category', 'name', defaults));
});

it('should accept (category, name, properties, options, callback)', function (done) {
defaults.category = 'category';
defaults.name = 'name';
analytics.page('category', 'name', {}, {}, function () {
assert(analytics._invoke.calledWith('page', 'category', 'name', properties, {}));
assert(analytics._invoke.calledWith('page', 'category', 'name', defaults, {}));
done();
});
});

it('should accept (category, name, properties, callback)', function (done) {
defaults.category = 'category';
defaults.name = 'name';
analytics.page('category', 'name', {}, function () {
assert(analytics._invoke.calledWith('page', 'category', 'name', properties));
assert(analytics._invoke.calledWith('page', 'category', 'name', defaults));
done();
});
});

it('should accept (category, name, callback)', function (done) {
defaults.category = 'category';
defaults.name = 'name';
analytics.page('category', 'name', function () {
assert(analytics._invoke.calledWith('page', 'category', 'name', properties));
assert(analytics._invoke.calledWith('page', 'category', 'name', defaults));
done();
});
});

it('should accept (name, properties, options, callback)', function (done) {
defaults.name = 'name';
analytics.page('name', {}, {}, function () {
assert(analytics._invoke.calledWith('page', null, 'name', properties, {}));
assert(analytics._invoke.calledWith('page', null, 'name', defaults, {}));
done();
});
});

it('should accept (name, properties, callback)', function (done) {
defaults.name = 'name';
analytics.page('name', {}, function () {
assert(analytics._invoke.calledWith('page', null, 'name', properties));
assert(analytics._invoke.calledWith('page', null, 'name', defaults));
done();
});
});

it('should accept (name, callback)', function (done) {
defaults.name = 'name';
analytics.page('name', function () {
assert(analytics._invoke.calledWith('page', null, 'name'));
done();
Expand All @@ -359,24 +371,26 @@ describe('Analytics', function () {

it('should accept (properties, options, callback)', function (done) {
analytics.page({}, {}, function () {
assert(analytics._invoke.calledWith('page', null, null, properties, {}));
assert(analytics._invoke.calledWith('page', null, null, defaults, {}));
done();
});
});

it('should accept (properties, callback)', function (done) {
analytics.page({}, function () {
assert(analytics._invoke.calledWith('page', null, null, properties));
assert(analytics._invoke.calledWith('page', null, null, defaults));
done();
});
});

it('should emit page', function (done) {
defaults.category = 'category';
defaults.name = 'name';
analytics.once('page', function (category, name, props, opts) {
assert('category' === category);
assert('name' === name);
assert(equal(opts, {}));
assert(equal(props, properties));
assert(equal(props, defaults));
done();
});
analytics.page('category', 'name', {}, {});
Expand Down

0 comments on commit 6f675b2

Please sign in to comment.