Skip to content

Commit

Permalink
chore(release): td.js version 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarandreu committed Sep 3, 2014
1 parent ed8db33 commit c7ec123
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 23 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.2.0

* Removed broken AMD snippet
* Manually set domain now overwrites default behavior
* IPv4 and localhost now gets cookie set as expected
* Cookie expiration is now set as expected
* When domain is not set it will attempt to recursively set the cookie on top domain until it succeeds. For example, with domains: `bar.foo.com`, `baz.foo.com`, `foo.com`. It will attempt setting the cookie on `.com` and it'll fail, then it'll try to set it on `.foo.com` and it'll succeed. All three domains will use the `.foo.com` cookie.

## 1.1.1

* td_referrer was not being set correctly, it should be using `document.referrer`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Install the td-js-sdk on your page by copying the JavaScript snippet below and p

```html
<script type="text/javascript">
!function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},s=["addRecord","set","trackEvent","trackPageview","ready"],n=0;n<s.length;n++){var i=s[n];e[t].prototype[i]=r(i)}var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"===document.location.protocol?"https:":"http:")+"//s3.amazonaws.com/td-cdn/sdk/td-1.1.1.js";var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c)}}("Treasure",this);
!function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},s=["addRecord","set","trackEvent","trackPageview","ready"],n=0;n<s.length;n++){var i=s[n];e[t].prototype[i]=r(i)}var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"===document.location.protocol?"https:":"http:")+"//s3.amazonaws.com/td-cdn/sdk/td-1.2.0.js";var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c)}}("Treasure",this);
</script>
```

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "td-js-sdk",
"version": "1.1.1",
"version": "1.2.0",
"homepage": "https://github.com/treasure-data/td-js-sdk",
"authors": [
"Cesar Andreu <[email protected]>"
Expand Down
49 changes: 34 additions & 15 deletions dist/td.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ var Treasure = require('./treasure.js');
// Load all cached clients
require('./loadClients')(Treasure);

if (typeof global.window.define === 'function' && global.window.define.amd) {
global.window.define('Treasure', function () { return Treasure; });
} else {
global.window.Treasure = Treasure;
}
global.window.Treasure = Treasure;

}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./loadClients":3,"./treasure.js":7,"es5-shim":19,"json3":22}],3:[function(require,module,exports){
Expand Down Expand Up @@ -328,7 +324,9 @@ function configureStorage (storage) {
_.defaults(storage, {
name: '_td',
expires: 63072000,
domain: document.location.hostname
domain: document.location.hostname,
customDomain: !!storage.domain,
path: '/'
});

return storage;
Expand Down Expand Up @@ -393,16 +391,37 @@ exports.configure = function configure (config) {
}
this.client.track.uuid = config.clientId;

// Keep trying to set cookie on top level domain until it's allowed
// Set cookie on highest allowed domain
var setCookie = function (storage, uuid) {
var clone = _.clone(storage);
var max = storage.domain.split('.').length;
for (var i = 0; i <= max; i++) {
clone.domain = storage.domain.split('.').slice(0 - i);
var clone = _.clone(storage),
is = {
ip: storage.domain.match(/\d*\.\d*\.\d*\.\d*$/),
local: storage.domain === 'localhost',
custom: storage.customDomain
};

// When it's localhost, an IP, or custom domain, set the cookie directly
if (is.ip || is.local || is.custom) {
clone.domain = is.local ? null : clone.domain;
cookie(storage.name, uuid, clone);
//
if (cookie.get(storage.name) && uuid) {
break;
} else {
// Otherwise iterate recursively on the domain until it gets set
// For example, if we have three sites:
// bar.foo.com, baz.foo.com, foo.com
// First it tries setting a cookie on .com, and it fails
// Then it sets the cookie on .foo.com, and it'll pass
var domain = storage.domain.split('.');
for (var i = domain.length - 1; i >= 0; i--) {
clone.domain = '.' + (domain.slice(i).join('.'));
cookie(storage.name, uuid, clone);

// Break when cookies aren't being cleared and it gets set properly
// Don't break when uuid is falsy so all the cookies get cleared
if (cookie.get(storage.name) && uuid) {
// When cookie is set succesfully, save used domain in storage object
storage.domain = clone.domain;
break;
}
}
}
};
Expand Down Expand Up @@ -757,7 +776,7 @@ module.exports = Treasure;
},{"./configurator":1,"./lodash":4,"./plugins/track":5,"./record":6,"./version":8,"domready":18}],8:[function(require,module,exports){
'use strict';

module.exports = '1.1.1';
module.exports = '1.2.0';

},{}],9:[function(require,module,exports){
/*!
Expand Down
8 changes: 4 additions & 4 deletions dist/td.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';

module.exports = '1.1.1';
module.exports = '1.2.0';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "td-js-sdk",
"version": "1.1.1",
"version": "1.2.0",
"bugs": "https://github.com/treasure-data/td-js-sdk/issues",
"description": "Browser JS library for sending events to your Treasure Data account",
"main": "dist/td.js",
Expand Down

0 comments on commit c7ec123

Please sign in to comment.