Skip to content

Commit b6ca44f

Browse files
committed
Cherry pick onInit function from 5.0.0
1 parent 40ff69f commit b6ca44f

10 files changed

+61
-8
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
### 4.6.0 (February 25, 2018)
1+
### 5.0.0 (Unreleased)
2+
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
5+
* 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).
11+
* Drop custom user agent parsing for symbian and blackberry
12+
13+
### 4.7.0 (March 12, 2019)
14+
15+
* Cherry-picked from 5.0.0: Add `onInit` method that accepts a callback that will be invoked after init
16+
17+
### 4.6.0 (February 25, 2019)
218

319
* Add support for unsetting utm params when a new session is created
420
* Update dependencies to pass yarn audit

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Please see our [installation guide](https://amplitude.zendesk.com/hc/en-us/artic
1111
[![npm version](https://badge.fury.io/js/amplitude-js.svg)](https://badge.fury.io/js/amplitude-js)
1212
[![Bower version](https://badge.fury.io/bo/amplitude-js.svg)](https://badge.fury.io/bo/amplitude-js)
1313

14-
[4.6.0 - Released on February 25, 2019](https://github.com/amplitude/Amplitude-JavaScript/releases/latest)
14+
[4.7.0 - Released on March 12, 2019](https://github.com/amplitude/Amplitude-JavaScript/releases/latest)
1515

1616

1717
# JavaScript SDK Reference #

amplitude-snippet.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function(e,t){var n=e.amplitude||{_q:[],_iq:{}};var r=t.createElement("script")
22
;r.type="text/javascript";r.async=true
3-
;r.src="https://cdn.amplitude.com/libs/amplitude-4.6.0-min.gz.js"
3+
;r.src="https://cdn.amplitude.com/libs/amplitude-4.7.0-min.gz.js"
44
;r.onload=function(){if(e.amplitude.runQueuedFunctions){
55
e.amplitude.runQueuedFunctions()}else{
66
console.log("[Amplitude] Error: could not load SDK")}}

amplitude.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3801,7 +3801,7 @@ var uuid = function uuid(a) {
38013801
);
38023802
};
38033803

3804-
var version = '4.6.0';
3804+
var version = '4.7.0';
38053805

38063806
var getLanguage = function getLanguage() {
38073807
return navigator && (navigator.languages && navigator.languages[0] || navigator.language || navigator.userLanguage) || undefined;
@@ -3871,6 +3871,7 @@ var AmplitudeClient = function AmplitudeClient(instanceName) {
38713871
this._q = []; // queue for proxied functions before script load
38723872
this._sending = false;
38733873
this._updateScheduled = false;
3874+
this._onInit = [];
38743875

38753876
// event meta data
38763877
this._eventId = 0;
@@ -3983,6 +3984,10 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
39833984
opt_callback(this);
39843985
}
39853986
}
3987+
3988+
for (var _i = 0; _i < this._onInit.length; _i++) {
3989+
this._onInit[_i]();
3990+
}
39863991
};
39873992

39883993
/**
@@ -4118,6 +4123,14 @@ AmplitudeClient.prototype.isNewSession = function isNewSession() {
41184123
return this._newSession;
41194124
};
41204125

4126+
/**
4127+
* Store callbacks to call after init
4128+
* @private
4129+
*/
4130+
AmplitudeClient.prototype.onInit = function (callback) {
4131+
this._onInit.push(callback);
4132+
};
4133+
41214134
/**
41224135
* Returns the id of the current session.
41234136
* @public

amplitude.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "amplitude-js",
33
"author": "Amplitude <[email protected]>",
4-
"version": "4.6.0",
4+
"version": "4.7.0",
55
"license": "MIT",
66
"description": "Javascript library for Amplitude Analytics",
77
"keywords": [

src/amplitude-client.js

Lines changed: 13 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,10 @@ 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+
}
152157
};
153158

154159
/**
@@ -285,6 +290,14 @@ AmplitudeClient.prototype.isNewSession = function isNewSession() {
285290
return this._newSession;
286291
};
287292

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

src/amplitude-snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
var as = document.createElement('script');
44
as.type = 'text/javascript';
55
as.async = true;
6-
as.src = 'https://cdn.amplitude.com/libs/amplitude-4.6.0-min.gz.js';
6+
as.src = 'https://cdn.amplitude.com/libs/amplitude-4.7.0-min.gz.js';
77
as.onload = function() {if(window.amplitude.runQueuedFunctions) {window.amplitude.runQueuedFunctions();} else {console.log('[Amplitude] Error: could not load SDK');}};
88
var s = document.getElementsByTagName('script')[0];
99
s.parentNode.insertBefore(as, s);

src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export default '4.6.0';
1+
export default '4.7.0';

test/amplitude-client.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ describe('AmplitudeClient', function() {
5454
assert.equal(new AmplitudeClient('$DEFAULT_INSTANCE')._instanceName, '$default_instance');
5555
});
5656

57+
it('should invoke onInit callbacks', function() {
58+
let onInitCalled = false;
59+
let onInit2Called = false;
60+
amplitude.onInit(() => { onInitCalled = true; });
61+
amplitude.onInit(() => { onInit2Called = true; });
62+
63+
amplitude.init(apiKey);
64+
assert.ok(onInitCalled);
65+
assert.ok(onInit2Called);
66+
});
67+
5768
it('fails on invalid apiKeys', function() {
5869
amplitude.init(null);
5970
assert.equal(amplitude.options.apiKey, undefined);

0 commit comments

Comments
 (0)