@ninetailed/experience.js 2.1.0 → 2.1.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.esm.js +44 -10
- package/index.umd.js +95 -10
- package/lib/Ninetailed.d.ts +8 -2
- package/package.json +2 -2
package/index.esm.js
CHANGED
|
@@ -3054,6 +3054,7 @@ const ninetailedPlugin = ({
|
|
|
3054
3054
|
}
|
|
3055
3055
|
|
|
3056
3056
|
isInitialized = true;
|
|
3057
|
+
logger.debug('Ninetailed Core plugin initialized.');
|
|
3057
3058
|
},
|
|
3058
3059
|
page: ({
|
|
3059
3060
|
payload,
|
|
@@ -3163,22 +3164,26 @@ class Ninetailed {
|
|
|
3163
3164
|
onLog,
|
|
3164
3165
|
onError
|
|
3165
3166
|
} = {}) {
|
|
3166
|
-
this.
|
|
3167
|
+
this.isInitialized = false;
|
|
3168
|
+
|
|
3169
|
+
this.page = (data, options) => __awaiter(this, void 0, void 0, function* () {
|
|
3170
|
+
yield this.waitUntilInitialized();
|
|
3167
3171
|
return this.instance.page(data, this.buildOptions(options));
|
|
3168
|
-
};
|
|
3172
|
+
});
|
|
3169
3173
|
|
|
3170
|
-
this.track = (event, payload, options) => {
|
|
3174
|
+
this.track = (event, payload, options) => __awaiter(this, void 0, void 0, function* () {
|
|
3175
|
+
yield this.waitUntilInitialized();
|
|
3171
3176
|
return this.instance.track(event, payload, this.buildOptions(options));
|
|
3172
|
-
};
|
|
3177
|
+
});
|
|
3173
3178
|
|
|
3174
|
-
this.trackHasSeenComponent = payload => {
|
|
3179
|
+
this.trackHasSeenComponent = payload => __awaiter(this, void 0, void 0, function* () {
|
|
3175
3180
|
return this.track('hasSeenComponent', payload, {
|
|
3176
3181
|
plugins: {
|
|
3177
3182
|
all: true,
|
|
3178
3183
|
ninetailed: false
|
|
3179
3184
|
}
|
|
3180
3185
|
});
|
|
3181
|
-
};
|
|
3186
|
+
});
|
|
3182
3187
|
|
|
3183
3188
|
this.trackExperience = payload => {
|
|
3184
3189
|
return this.track('nt_experience', payload, {
|
|
@@ -3189,16 +3194,21 @@ class Ninetailed {
|
|
|
3189
3194
|
});
|
|
3190
3195
|
};
|
|
3191
3196
|
|
|
3192
|
-
this.identify = (uid, traits, options) => {
|
|
3197
|
+
this.identify = (uid, traits, options) => __awaiter(this, void 0, void 0, function* () {
|
|
3198
|
+
yield this.waitUntilInitialized();
|
|
3193
3199
|
return this.instance.identify(uid, traits, this.buildOptions(options));
|
|
3194
|
-
};
|
|
3200
|
+
});
|
|
3195
3201
|
|
|
3196
3202
|
this.reset = () => {
|
|
3197
|
-
|
|
3203
|
+
this.onIsInitialized(() => {
|
|
3204
|
+
this.instance.plugins[PLUGIN_NAME].reset();
|
|
3205
|
+
});
|
|
3198
3206
|
};
|
|
3199
3207
|
|
|
3200
3208
|
this.debug = enabled => {
|
|
3201
|
-
|
|
3209
|
+
this.onIsInitialized(() => {
|
|
3210
|
+
this.instance.plugins[PLUGIN_NAME].debug(enabled);
|
|
3211
|
+
});
|
|
3202
3212
|
};
|
|
3203
3213
|
|
|
3204
3214
|
this.onProfileChange = cb => {
|
|
@@ -3214,6 +3224,25 @@ class Ninetailed {
|
|
|
3214
3224
|
});
|
|
3215
3225
|
};
|
|
3216
3226
|
|
|
3227
|
+
this.onIsInitialized = onIsInitialized => {
|
|
3228
|
+
if (typeof onIsInitialized === 'function') {
|
|
3229
|
+
if (this.isInitialized) {
|
|
3230
|
+
onIsInitialized();
|
|
3231
|
+
} else {
|
|
3232
|
+
const detachOnReadyListener = this.instance.on('ready', () => {
|
|
3233
|
+
onIsInitialized();
|
|
3234
|
+
detachOnReadyListener();
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
};
|
|
3239
|
+
|
|
3240
|
+
this.waitUntilInitialized = () => {
|
|
3241
|
+
return new Promise(resolve => {
|
|
3242
|
+
this.onIsInitialized(resolve);
|
|
3243
|
+
});
|
|
3244
|
+
};
|
|
3245
|
+
|
|
3217
3246
|
this.plugins = flatten(plugins || []);
|
|
3218
3247
|
|
|
3219
3248
|
if (profile) {
|
|
@@ -3252,6 +3281,11 @@ class Ninetailed {
|
|
|
3252
3281
|
requestTimeout,
|
|
3253
3282
|
preview
|
|
3254
3283
|
})]
|
|
3284
|
+
});
|
|
3285
|
+
const detachOnReadyListener = this.instance.on('ready', () => {
|
|
3286
|
+
this.isInitialized = true;
|
|
3287
|
+
logger.info('Ninetailed Experience.js SDK is completely initialized.');
|
|
3288
|
+
detachOnReadyListener();
|
|
3255
3289
|
}); // put in private method
|
|
3256
3290
|
|
|
3257
3291
|
this.onProfileChange(profileState => {
|
package/index.umd.js
CHANGED
|
@@ -2880,6 +2880,7 @@
|
|
|
2880
2880
|
}
|
|
2881
2881
|
|
|
2882
2882
|
isInitialized = true;
|
|
2883
|
+
logger.debug('Ninetailed Core plugin initialized.');
|
|
2883
2884
|
},
|
|
2884
2885
|
page: function (_a) {
|
|
2885
2886
|
var payload = _a.payload,
|
|
@@ -3107,20 +3108,60 @@
|
|
|
3107
3108
|
onLog = _c.onLog,
|
|
3108
3109
|
onError = _c.onError;
|
|
3109
3110
|
|
|
3111
|
+
this.isInitialized = false;
|
|
3112
|
+
|
|
3110
3113
|
this.page = function (data, options) {
|
|
3111
|
-
return _this
|
|
3114
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
3115
|
+
return __generator(this, function (_a) {
|
|
3116
|
+
switch (_a.label) {
|
|
3117
|
+
case 0:
|
|
3118
|
+
return [4
|
|
3119
|
+
/*yield*/
|
|
3120
|
+
, this.waitUntilInitialized()];
|
|
3121
|
+
|
|
3122
|
+
case 1:
|
|
3123
|
+
_a.sent();
|
|
3124
|
+
|
|
3125
|
+
return [2
|
|
3126
|
+
/*return*/
|
|
3127
|
+
, this.instance.page(data, this.buildOptions(options))];
|
|
3128
|
+
}
|
|
3129
|
+
});
|
|
3130
|
+
});
|
|
3112
3131
|
};
|
|
3113
3132
|
|
|
3114
3133
|
this.track = function (event, payload, options) {
|
|
3115
|
-
return _this
|
|
3134
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
3135
|
+
return __generator(this, function (_a) {
|
|
3136
|
+
switch (_a.label) {
|
|
3137
|
+
case 0:
|
|
3138
|
+
return [4
|
|
3139
|
+
/*yield*/
|
|
3140
|
+
, this.waitUntilInitialized()];
|
|
3141
|
+
|
|
3142
|
+
case 1:
|
|
3143
|
+
_a.sent();
|
|
3144
|
+
|
|
3145
|
+
return [2
|
|
3146
|
+
/*return*/
|
|
3147
|
+
, this.instance.track(event, payload, this.buildOptions(options))];
|
|
3148
|
+
}
|
|
3149
|
+
});
|
|
3150
|
+
});
|
|
3116
3151
|
};
|
|
3117
3152
|
|
|
3118
3153
|
this.trackHasSeenComponent = function (payload) {
|
|
3119
|
-
return _this
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3154
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
3155
|
+
return __generator(this, function (_a) {
|
|
3156
|
+
return [2
|
|
3157
|
+
/*return*/
|
|
3158
|
+
, this.track('hasSeenComponent', payload, {
|
|
3159
|
+
plugins: {
|
|
3160
|
+
all: true,
|
|
3161
|
+
ninetailed: false
|
|
3162
|
+
}
|
|
3163
|
+
})];
|
|
3164
|
+
});
|
|
3124
3165
|
});
|
|
3125
3166
|
};
|
|
3126
3167
|
|
|
@@ -3134,15 +3175,35 @@
|
|
|
3134
3175
|
};
|
|
3135
3176
|
|
|
3136
3177
|
this.identify = function (uid, traits, options) {
|
|
3137
|
-
return _this
|
|
3178
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
3179
|
+
return __generator(this, function (_a) {
|
|
3180
|
+
switch (_a.label) {
|
|
3181
|
+
case 0:
|
|
3182
|
+
return [4
|
|
3183
|
+
/*yield*/
|
|
3184
|
+
, this.waitUntilInitialized()];
|
|
3185
|
+
|
|
3186
|
+
case 1:
|
|
3187
|
+
_a.sent();
|
|
3188
|
+
|
|
3189
|
+
return [2
|
|
3190
|
+
/*return*/
|
|
3191
|
+
, this.instance.identify(uid, traits, this.buildOptions(options))];
|
|
3192
|
+
}
|
|
3193
|
+
});
|
|
3194
|
+
});
|
|
3138
3195
|
};
|
|
3139
3196
|
|
|
3140
3197
|
this.reset = function () {
|
|
3141
|
-
|
|
3198
|
+
_this.onIsInitialized(function () {
|
|
3199
|
+
_this.instance.plugins[PLUGIN_NAME].reset();
|
|
3200
|
+
});
|
|
3142
3201
|
};
|
|
3143
3202
|
|
|
3144
3203
|
this.debug = function (enabled) {
|
|
3145
|
-
|
|
3204
|
+
_this.onIsInitialized(function () {
|
|
3205
|
+
_this.instance.plugins[PLUGIN_NAME].debug(enabled);
|
|
3206
|
+
});
|
|
3146
3207
|
};
|
|
3147
3208
|
|
|
3148
3209
|
this.onProfileChange = function (cb) {
|
|
@@ -3157,6 +3218,25 @@
|
|
|
3157
3218
|
});
|
|
3158
3219
|
};
|
|
3159
3220
|
|
|
3221
|
+
this.onIsInitialized = function (onIsInitialized) {
|
|
3222
|
+
if (typeof onIsInitialized === 'function') {
|
|
3223
|
+
if (_this.isInitialized) {
|
|
3224
|
+
onIsInitialized();
|
|
3225
|
+
} else {
|
|
3226
|
+
var detachOnReadyListener_1 = _this.instance.on('ready', function () {
|
|
3227
|
+
onIsInitialized();
|
|
3228
|
+
detachOnReadyListener_1();
|
|
3229
|
+
});
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
};
|
|
3233
|
+
|
|
3234
|
+
this.waitUntilInitialized = function () {
|
|
3235
|
+
return new Promise(function (resolve) {
|
|
3236
|
+
_this.onIsInitialized(resolve);
|
|
3237
|
+
});
|
|
3238
|
+
};
|
|
3239
|
+
|
|
3160
3240
|
this.plugins = flatten__default["default"](plugins || []);
|
|
3161
3241
|
|
|
3162
3242
|
if (profile) {
|
|
@@ -3195,6 +3275,11 @@
|
|
|
3195
3275
|
requestTimeout: requestTimeout,
|
|
3196
3276
|
preview: preview
|
|
3197
3277
|
})], false)
|
|
3278
|
+
});
|
|
3279
|
+
var detachOnReadyListener = this.instance.on('ready', function () {
|
|
3280
|
+
_this.isInitialized = true;
|
|
3281
|
+
logger.info('Ninetailed Experience.js SDK is completely initialized.');
|
|
3282
|
+
detachOnReadyListener();
|
|
3198
3283
|
}); // put in private method
|
|
3199
3284
|
|
|
3200
3285
|
this.onProfileChange(function (profileState) {
|
package/lib/Ninetailed.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ declare global {
|
|
|
13
13
|
} & unknown;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
declare type OnIsInitializedCallback = () => void;
|
|
17
|
+
export declare type OnIsInitialized = (cb: OnIsInitializedCallback) => void;
|
|
16
18
|
declare type Options = {
|
|
17
19
|
url?: string;
|
|
18
20
|
locale?: Locale;
|
|
@@ -62,10 +64,12 @@ export interface NinetailedInstance {
|
|
|
62
64
|
onProfileChange: OnProfileChange;
|
|
63
65
|
plugins: AnalyticsPlugin[];
|
|
64
66
|
logger: Logger;
|
|
67
|
+
onIsInitialized: OnIsInitialized;
|
|
65
68
|
}
|
|
66
69
|
export declare class Ninetailed implements NinetailedInstance {
|
|
67
70
|
private readonly instance;
|
|
68
71
|
private _profileState;
|
|
72
|
+
private isInitialized;
|
|
69
73
|
readonly plugins: AnalyticsPlugin[];
|
|
70
74
|
readonly logger: Logger;
|
|
71
75
|
constructor({ clientId, environment, preview, }: {
|
|
@@ -78,9 +82,11 @@ export declare class Ninetailed implements NinetailedInstance {
|
|
|
78
82
|
trackHasSeenComponent: TrackHasSeenComponent;
|
|
79
83
|
trackExperience: TrackExperience;
|
|
80
84
|
identify: (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<any>;
|
|
81
|
-
reset: () =>
|
|
82
|
-
debug: (enabled: boolean) =>
|
|
85
|
+
reset: () => void;
|
|
86
|
+
debug: (enabled: boolean) => void;
|
|
83
87
|
onProfileChange: (cb: OnProfileChangeCallback) => DetachListeners;
|
|
88
|
+
onIsInitialized: (onIsInitialized: OnIsInitializedCallback) => void;
|
|
89
|
+
private waitUntilInitialized;
|
|
84
90
|
get profileState(): ProfileState;
|
|
85
91
|
private buildOptions;
|
|
86
92
|
private registerWindowHandlers;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1-beta.1",
|
|
4
4
|
"main": "./index.umd.js",
|
|
5
5
|
"module": "./index.esm.js",
|
|
6
6
|
"typings": "./index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"analytics": "^0.8.0",
|
|
9
|
-
"@ninetailed/experience.js-shared": "2.1.
|
|
9
|
+
"@ninetailed/experience.js-shared": "2.1.1-beta.1",
|
|
10
10
|
"uuid": "^8.3.2",
|
|
11
11
|
"ts-toolbelt": "^9.6.0",
|
|
12
12
|
"locale-enum": "^1.1.1",
|