Skip to content

Commit cd7bfce

Browse files
authored
Add onInit hook, drop json3, update build dependencies (#178)
* Drop json3 polyfill and update build dependencies * fix uri tests and build * add onInit hook to invoke callbacks after init * Add onInit to snippet * Clear onInit queue
1 parent 6ee5164 commit cd7bfce

20 files changed

+929
-794
lines changed

.babelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"presets": [
3-
["env", {
3+
["@babel/env", {
44
"targets": {
5-
"browsers": ["ie >= 9"]
5+
"browsers": ["ie >= 8"]
66
},
77
"modules": false
88
}]

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
### 5.0.0 (February 27, 2019)
1+
### 5.0.0 (Unreleased)
22

3-
* Stop committing generated files to the git repository
3+
* Add `onInit` method that accepts a callback that will be invoked after init
4+
* Allow for api endpoints that do not end with a trailing slash
45
* Sync with upstream ua-parser for user agent parsing
6+
* Upgrade rollup/babel dependencies
7+
8+
## Breaking Changes
9+
* Drop JSON polyfill. This will break IE 7 and older. You can install your own JSON polyfill before loading amplitude.
10+
* Stop committing generated files to the master branch in the git repository (do not install amplitude from git).
511
* Drop custom user agent parsing for symbian and blackberry
612

13+
14+
### 4.7.0 (March 12, 2019)
15+
16+
* Cherry-picked from 5.0.0: Add `onInit` method that accepts a callback that will be invoked after init
17+
718
### 4.6.0 (February 25, 2019)
819

920
* Add support for unsetting utm params when a new session is created

amplitude-segment-snippet.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var i=function(){this._q=[];return this}
77
;return this}
88
;var u=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"]
99
;for(var c=0;c<u.length;c++){r(a,u[c])}n.Revenue=a
10-
;var p=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"]
10+
;var p=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","groupIdentify","onInit","logEventWithTimestamp","logEventWithGroups","setSessionId","resetSessionId"]
1111
;function l(e){function t(t){e[t]=function(){
1212
e._q.push([t].concat(Array.prototype.slice.call(arguments,0)))}}
1313
for(var n=0;n<p.length;n++){t(p[n])}}l(n);n.getInstance=function(e){

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
"dependencies": {
1414
"@amplitude/ua-parser-js": "0.7.20",
1515
"blueimp-md5": "^2.10.0",
16-
"json3": "^3.3.2",
1716
"query-string": "5"
1817
},
1918
"devDependencies": {
20-
"babel-core": "6",
21-
"babel-plugin-external-helpers": "^6.22.0",
22-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
23-
"babel-polyfill": "^6.26.0",
24-
"babel-preset-env": "1",
19+
"@babel/core": "^7.3.4",
20+
"@babel/plugin-external-helpers": "^7.2.0",
21+
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
22+
"@babel/preset-env": "^7.3.4",
2523
"chai": "^4.1.2",
2624
"express": "^4.16.2",
2725
"fs-extra": "^4.0.2",
@@ -37,14 +35,14 @@
3735
"karma-sinon": "^1.0.5",
3836
"karma-sourcemap-loader": "^0.3.7",
3937
"mocha": "^4.0.1",
40-
"rollup": "^0.56.0",
41-
"rollup-plugin-babel": "^3.0.2",
42-
"rollup-plugin-commonjs": "8.4.1",
38+
"requirejs": "^2.3.6",
39+
"rollup": "^1.4.1",
40+
"rollup-plugin-babel": "^4.3.2",
41+
"rollup-plugin-commonjs": "^9.2.1",
4342
"rollup-plugin-legacy": "^1.0.0",
44-
"rollup-plugin-node-resolve": "^3.0.0",
43+
"rollup-plugin-node-resolve": "^4.0.1",
4544
"rollup-plugin-replace": "^2.1.0",
46-
"rollup-plugin-uglify": "^2.0.1",
47-
"saucelabs": "^1.5.0",
45+
"rollup-plugin-uglify": "^6.0.2",
4846
"sinon": "^4.1.2",
4947
"uglify-js": "^2.0.0"
5048
},

rollup.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import replace from 'rollup-plugin-replace';
44
import babel from 'rollup-plugin-babel';
55

66
export default {
7-
input: 'src/index.compat.js',
7+
input: 'src/index.js',
88
output: {
99
name: 'amplitude',
1010
file: 'amplitude.js',
@@ -13,8 +13,7 @@ export default {
1313
plugins: [
1414
babel({
1515
exclude: 'node_modules/**',
16-
externalHelpersWhitelist: ['defineProperty', 'extends', 'typeof'],
17-
plugins: ['external-helpers', 'transform-object-rest-spread'],
16+
plugins: ['@babel/plugin-proposal-object-rest-spread'],
1817
}),
1918
resolve({
2019
browser: true,
@@ -26,4 +25,4 @@ export default {
2625
}),
2726
commonjs(),
2827
],
29-
}
28+
};

rollup.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import config from './rollup.config.js';
2-
import uglify from 'rollup-plugin-uglify';
2+
import { uglify } from 'rollup-plugin-uglify';
33

44
config.plugins.push(uglify());
55
config.output.file = 'amplitude.min.js';

rollup.nocompat.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ export default {
1313
plugins: [
1414
babel({
1515
exclude: 'node_modules/**',
16-
externalHelpersWhitelist: ['defineProperty', 'extends', 'typeof'],
17-
plugins: ['external-helpers', 'transform-object-rest-spread'],
16+
plugins: ['@babel/plugin-proposal-object-rest-spread'],
1817
}),
1918
resolve({
2019
browser: true,
@@ -24,6 +23,12 @@ export default {
2423
BUILD_COMPAT_2_0: 'false',
2524
BUILD_COMPAT_LOCAL_STORAGE: 'false',
2625
}),
27-
commonjs(),
26+
commonjs({
27+
include: [
28+
'node_modules/query-string/**',
29+
'node_modules/@amplitude/ua-parser-js/**',
30+
'node_modules/blueimp-md5/**',
31+
],
32+
}),
2833
],
29-
}
34+
};

rollup.nocompat.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import config from './rollup.nocompat.js';
2-
import uglify from 'rollup-plugin-uglify';
2+
import { uglify } from 'rollup-plugin-uglify';
33

44
config.plugins.push(uglify());
55
config.output.file = 'amplitude.nocompat.min.js';

src/amplitude-client.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var AmplitudeClient = function AmplitudeClient(instanceName) {
3131
this._q = []; // queue for proxied functions before script load
3232
this._sending = false;
3333
this._updateScheduled = false;
34+
this._onInit = [];
3435

3536
// event meta data
3637
this._eventId = 0;
@@ -149,6 +150,11 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
149150
opt_callback(this);
150151
}
151152
}
153+
154+
for (let i = 0; i < this._onInit.length; i++) {
155+
this._onInit[i]();
156+
}
157+
this._onInit = [];
152158
};
153159

154160
/**
@@ -285,6 +291,14 @@ AmplitudeClient.prototype.isNewSession = function isNewSession() {
285291
return this._newSession;
286292
};
287293

294+
/**
295+
* Store callbacks to call after init
296+
* @private
297+
*/
298+
AmplitudeClient.prototype.onInit = function (callback) {
299+
this._onInit.push(callback);
300+
};
301+
288302
/**
289303
* Returns the id of the current session.
290304
* @public

src/amplitude-snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var funcs = ['init', 'logEvent', 'logRevenue', 'setUserId', 'setUserProperties',
2424
'setOptOut', 'setVersionName', 'setDomain', 'setDeviceId',
2525
'setGlobalUserProperties', 'identify', 'clearUserProperties',
26-
'setGroup', 'logRevenueV2', 'regenerateDeviceId', 'groupIdentify',
26+
'setGroup', 'logRevenueV2', 'regenerateDeviceId', 'groupIdentify', 'onInit',
2727
'logEventWithTimestamp', 'logEventWithGroups', 'setSessionId', 'resetSessionId'];
2828
function setUpProxy(instance) {
2929
function proxyMain(fn) {

0 commit comments

Comments
 (0)