Skip to content

Commit

Permalink
chore(release): td.js version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarandreu committed Aug 7, 2014
1 parent 05f3776 commit f380946
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 71 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 1.1.0

* Fix issue where domain and expiration were not passed to tracking cookie setter
* Tracking cookie is now always set on the top level qualified domain
* `expiration` key renamed to `expires`
* Remove `none` option from cookie domain settings

## 1.0.0

* Convert to CommonJS with Browserify
Expand Down
6 changes: 3 additions & 3 deletions 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.0.0.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.1.0.js";var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c)}}("Treasure",this);
</script>
```

Expand Down Expand Up @@ -164,8 +164,8 @@ If the database does not exist and you have permissions, it will be created for
* **config.clientId** : String (optional) - uuid for this client. When undefined it will attempt fetching the value from a cookie if storage is enabled, if none is found it will generate a v4 uuid
* **config.storage** : Object | String (optional) - storage configuration object. When `none` it will disable cookie storage
* **config.storage.name** : String (optional) - cookie name. Default: `_td`
* **config.storage.expiration** : Number (optional) - cookie expiration in seconds. When 0 it will expire with the session. Default: `63072000` (2 years)
* **config.storage.domain** : String (optional) - cookie domain. Set to `none` to use the browser default. Default: result of `tldjs.getDomain(document.location.host)`, [tldjs](https://github.com/oncletom/tld.js) is a library to get the qualified domain from a host string
* **config.storage.expires** : Number (optional) - cookie expiration in seconds. When 0 it will expire with the session. Default: `63072000` (2 years)
* **config.storage.domain** : String (optional) - cookie domain. Default: result of `document.location.hostname`

**Returns:**

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.0.0",
"version": "1.1.0",
"homepage": "https://github.com/treasure-data/td-js-sdk",
"authors": [
"Cesar Andreu <[email protected]>"
Expand Down
151 changes: 89 additions & 62 deletions dist/td.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,10 @@ function configureStorage (storage) {
storage = _.isObject(storage) ? storage : {};
_.defaults(storage, {
name: '_td',
expiration: 63072000,
expires: 63072000,
domain: document.location.hostname
});

if (storage.domain === 'none') {
storage.domain = undefined;
}

return storage;
}

Expand All @@ -360,13 +356,12 @@ function generateUUID () {
* config.storage.name (String)
* - cookie name
* - defaults to _td
* config.storage.expiration (Number)
* config.storage.expires (Number)
* - cookie duration in seconds
* - when 0 no cookie gets set
* - defaults to 63072000 (2 years)
* config.storage.domain (String)
* - domain on which to set the cookie
* - when 'none' it will use browser default
* - defaults to document.location.hostname
* config.track (Object)
* - tracking configuration object
Expand Down Expand Up @@ -398,13 +393,32 @@ exports.configure = function configure (config) {
}
this.client.track.uuid = config.clientId;

// We only save cookies if storage is enabled and expiration is non-zero
// Future work: save on top level domain that gets allowed
// For example: www.google.com and foo.google.com, should save to google.com
// Expire all domain cookies
var expireCookie = function (storage) {
var max = (storage.domain || '').split('.').length;
for (var i = 0; i <= max; i++) {
cookie.expire(storage.name);
}
};

// Keep trying to set cookie on top level domain until it's allowed
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);
cookie(storage.name, uuid, clone);
if (cookie.get(storage.name)) {
break;
}
}
};

// Only save cookies if storage is enabled and expires is non-zero
if (config.storage) {
cookie.expire(config.storage.name);
if (config.storage.expiration) {
cookie.set(config.storage.name, this.client.track.uuid);
if (config.storage.expires) {
expireCookie(config.storage);
setCookie(config.storage, this.client.track.uuid);
}
}

Expand Down Expand Up @@ -749,7 +763,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.0.0';
module.exports = '1.1.0';

},{}],9:[function(require,module,exports){
/*!
Expand All @@ -768,22 +782,35 @@ exports.INSPECT_MAX_BYTES = 50
Buffer.poolSize = 8192

/**
* If `Buffer._useTypedArrays`:
* If `TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Use Object implementation (compatible down to IE6)
* === false Use Object implementation (most compatible, even IE6)
*
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
* Opera 11.6+, iOS 4.2+.
*
* Note:
*
* - Implementation must support adding new properties to `Uint8Array` instances.
* Firefox 4-29 lacked support, fixed in Firefox 30+.
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
*
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
*
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
* incorrect length in some situations.
*
* We detect these buggy browsers and set `TYPED_ARRAY_SUPPORT` to `false` so they will
* get the Object implementation, which is slower but will work correctly.
*/
Buffer._useTypedArrays = (function () {
// Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+,
// Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding
// properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support
// because we need to be able to add all the node Buffer API methods. This is an issue
// in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
var TYPED_ARRAY_SUPPORT = (function () {
try {
var buf = new ArrayBuffer(0)
var arr = new Uint8Array(buf)
arr.foo = function () { return 42 }
return 42 === arr.foo() &&
typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray`
return 42 === arr.foo() && // typed array instances can be augmented
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
} catch (e) {
return false
}
Expand All @@ -807,23 +834,23 @@ function Buffer (subject, encoding, noZero) {

var type = typeof subject

if (encoding === 'base64' && type === 'string') {
subject = base64clean(subject)
}

// Find the length
var length
if (type === 'number')
length = coerce(subject)
else if (type === 'string')
length = subject > 0 ? subject >>> 0 : 0
else if (type === 'string') {
if (encoding === 'base64')
subject = base64clean(subject)
length = Buffer.byteLength(subject, encoding)
else if (type === 'object')
length = coerce(subject.length) // assume that object is array-like
else
} else if (type === 'object' && subject !== null) { // assume object is array-like
if (subject.type === 'Buffer' && isArray(subject.data))
subject = subject.data
length = +subject.length > 0 ? Math.floor(+subject.length) : 0
} else
throw new Error('First argument needs to be a number, array or string.')

var buf
if (Buffer._useTypedArrays) {
if (TYPED_ARRAY_SUPPORT) {
// Preferred: Return an augmented `Uint8Array` instance for best performance
buf = Buffer._augment(new Uint8Array(length))
} else {
Expand All @@ -834,7 +861,7 @@ function Buffer (subject, encoding, noZero) {
}

var i
if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') {
if (TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') {
// Speed optimization -- use set if we're copying from a typed array
buf._set(subject)
} else if (isArrayish(subject)) {
Expand All @@ -848,7 +875,7 @@ function Buffer (subject, encoding, noZero) {
}
} else if (type === 'string') {
buf.write(subject, 0, encoding)
} else if (type === 'number' && !Buffer._useTypedArrays && !noZero) {
} else if (type === 'number' && !TYPED_ARRAY_SUPPORT && !noZero) {
for (i = 0; i < length; i++) {
buf[i] = 0
}
Expand Down Expand Up @@ -880,7 +907,7 @@ Buffer.isEncoding = function (encoding) {
}

Buffer.isBuffer = function (b) {
return !!(b !== null && b !== undefined && b._isBuffer)
return !!(b != null && b._isBuffer)
}

Buffer.byteLength = function (str, encoding) {
Expand Down Expand Up @@ -1155,7 +1182,7 @@ Buffer.prototype.copy = function (target, target_start, start, end) {

var len = end - start

if (len < 100 || !Buffer._useTypedArrays) {
if (len < 100 || !TYPED_ARRAY_SUPPORT) {
for (var i = 0; i < len; i++) {
target[i + target_start] = this[i + start]
}
Expand Down Expand Up @@ -1227,10 +1254,29 @@ function utf16leSlice (buf, start, end) {

Buffer.prototype.slice = function (start, end) {
var len = this.length
start = clamp(start, len, 0)
end = clamp(end, len, len)
start = ~~start
end = end === undefined ? len : ~~end

if (start < 0) {
start += len;
if (start < 0)
start = 0
} else if (start > len) {
start = len
}

if (end < 0) {
end += len
if (end < 0)
end = 0
} else if (end > len) {
end = len
}

if (end < start)
end = start

if (Buffer._useTypedArrays) {
if (TYPED_ARRAY_SUPPORT) {
return Buffer._augment(this.subarray(start, end))
} else {
var sliceLen = end - start
Expand Down Expand Up @@ -1689,7 +1735,7 @@ Buffer.prototype.inspect = function () {
*/
Buffer.prototype.toArrayBuffer = function () {
if (typeof Uint8Array !== 'undefined') {
if (Buffer._useTypedArrays) {
if (TYPED_ARRAY_SUPPORT) {
return (new Buffer(this)).buffer
} else {
var buf = new Uint8Array(this.length)
Expand Down Expand Up @@ -1782,25 +1828,6 @@ function stringtrim (str) {
return str.replace(/^\s+|\s+$/g, '')
}

// slice(start, end)
function clamp (index, len, defaultValue) {
if (typeof index !== 'number') return defaultValue
index = ~~index; // Coerce to integer.
if (index >= len) return len
if (index >= 0) return index
index += len
if (index >= 0) return index
return 0
}

function coerce (length) {
// Coerce length to a number (possibly NaN), round up
// in case it's fractional (e.g. 123.456) then do a
// double negate to coerce a NaN to 0. Easy, right?
length = ~~Math.ceil(+length)
return length < 0 ? 0 : length
}

function isArray (subject) {
return (Array.isArray || function (subject) {
return Object.prototype.toString.call(subject) === '[object Array]'
Expand Down Expand Up @@ -3787,7 +3814,7 @@ var isArguments = function isArguments(value) {
var str = _toString.call(value);
var isArgs = str === '[object Arguments]';
if (!isArgs) {
isArgs = !isArray(str)
isArgs = !isArray(value)
&& value !== null
&& typeof value === 'object'
&& typeof value.length === 'number'
Expand Down
6 changes: 3 additions & 3 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.0.0';
module.exports = '1.1.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.0.0",
"version": "1.1.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 f380946

Please sign in to comment.