@firebase/analytics 0.9.5 → 0.10.0-canary.5a2ceb07b
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/CHANGELOG.md +6 -0
- package/dist/analytics-public.d.ts +10 -0
- package/dist/analytics.d.ts +10 -0
- package/dist/esm/index.esm.js +67 -10
- package/dist/esm/index.esm.js.map +1 -1
- package/dist/esm/index.esm2017.js +48 -8
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/api.d.ts +9 -0
- package/dist/esm/src/constants.d.ts +2 -1
- package/dist/esm/src/errors.d.ts +1 -0
- package/dist/esm/src/functions.d.ts +7 -0
- package/dist/esm/src/types.d.ts +2 -0
- package/dist/index.cjs.js +66 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/api.d.ts +9 -0
- package/dist/src/constants.d.ts +2 -1
- package/dist/src/errors.d.ts +1 -0
- package/dist/src/functions.d.ts +7 -0
- package/dist/src/types.d.ts +2 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @firebase/analytics
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`0a27d2fbf`](https://github.com/firebase/firebase-js-sdk/commit/0a27d2fbf268f07099d4fa5ecab7fbf35a579780) [#7158](https://github.com/firebase/firebase-js-sdk/pull/7158) - Add method `getGoogleAnalyticsClientId()` to retrieve an unique identifier for a web client. This allows users to log purchase and other events from their backends using Google Analytics 4 Measurement Protocol and to have those events be connected to actions taken on the client within their Firebase web app. `getGoogleAnalyticsClientId()` will simplify this event recording process.
|
|
8
|
+
|
|
3
9
|
## 0.9.5
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -174,6 +174,16 @@ export declare interface EventParams {
|
|
|
174
174
|
*/
|
|
175
175
|
export declare function getAnalytics(app?: FirebaseApp): Analytics;
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Retrieves a unique Google Analytics identifier for the web client.
|
|
179
|
+
* See {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/config#client_id | client_id}.
|
|
180
|
+
*
|
|
181
|
+
* @public
|
|
182
|
+
*
|
|
183
|
+
* @param app - The {@link @firebase/app#FirebaseApp} to use.
|
|
184
|
+
*/
|
|
185
|
+
export declare function getGoogleAnalyticsClientId(analyticsInstance: Analytics): Promise<string>;
|
|
186
|
+
|
|
177
187
|
/**
|
|
178
188
|
* A set of common Google Analytics config settings recognized by
|
|
179
189
|
* `gtag.js`.
|
package/dist/analytics.d.ts
CHANGED
|
@@ -174,6 +174,16 @@ export declare interface EventParams {
|
|
|
174
174
|
*/
|
|
175
175
|
export declare function getAnalytics(app?: FirebaseApp): Analytics;
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Retrieves a unique Google Analytics identifier for the web client.
|
|
179
|
+
* See {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/config#client_id | client_id}.
|
|
180
|
+
*
|
|
181
|
+
* @public
|
|
182
|
+
*
|
|
183
|
+
* @param app - The {@link @firebase/app#FirebaseApp} to use.
|
|
184
|
+
*/
|
|
185
|
+
export declare function getGoogleAnalyticsClientId(analyticsInstance: Analytics): Promise<string>;
|
|
186
|
+
|
|
177
187
|
/**
|
|
178
188
|
* A set of common Google Analytics config settings recognized by
|
|
179
189
|
* `gtag.js`.
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getApp, _getProvider, _registerComponent, registerVersion } from '@firebase/app';
|
|
2
|
-
import { __awaiter, __generator, __assign } from 'tslib';
|
|
2
|
+
import { __awaiter, __generator, __spreadArray, __assign } from 'tslib';
|
|
3
3
|
import { Logger } from '@firebase/logger';
|
|
4
4
|
import { ErrorFactory, calculateBackoffMillis, FirebaseError, validateIndexedDBOpenable, isIndexedDBAvailable, isBrowserExtension, areCookiesEnabled, getModularInstance, deepEqual } from '@firebase/util';
|
|
5
5
|
import { Component } from '@firebase/component';
|
|
@@ -92,6 +92,7 @@ var ERRORS = (_a = {},
|
|
|
92
92
|
'contain a valid API key.',
|
|
93
93
|
_a["no-app-id" /* AnalyticsError.NO_APP_ID */] = 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
|
|
94
94
|
'contain a valid app ID.',
|
|
95
|
+
_a["no-client-id" /* AnalyticsError.NO_CLIENT_ID */] = 'The "client_id" field is empty.',
|
|
95
96
|
_a["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */] = 'Trusted Types detected an invalid gtag resource: {$gtagURL}.',
|
|
96
97
|
_a);
|
|
97
98
|
var ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
|
|
@@ -335,36 +336,50 @@ measurementIdToAppId) {
|
|
|
335
336
|
* @param idOrNameOrParams Measurement ID if command is EVENT/CONFIG, params if command is SET.
|
|
336
337
|
* @param gtagParams Params if event is EVENT/CONFIG.
|
|
337
338
|
*/
|
|
338
|
-
function gtagWrapper(command
|
|
339
|
+
function gtagWrapper(command) {
|
|
340
|
+
var args = [];
|
|
341
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
342
|
+
args[_i - 1] = arguments[_i];
|
|
343
|
+
}
|
|
339
344
|
return __awaiter(this, void 0, void 0, function () {
|
|
340
|
-
var e_3;
|
|
345
|
+
var measurementId, gtagParams, measurementId, gtagParams, gtagParams, measurementId, fieldName, callback, customParams, e_3;
|
|
341
346
|
return __generator(this, function (_a) {
|
|
342
347
|
switch (_a.label) {
|
|
343
348
|
case 0:
|
|
344
349
|
_a.trys.push([0, 6, , 7]);
|
|
345
350
|
if (!(command === "event" /* GtagCommand.EVENT */)) return [3 /*break*/, 2];
|
|
351
|
+
measurementId = args[0], gtagParams = args[1];
|
|
346
352
|
// If EVENT, second arg must be measurementId.
|
|
347
|
-
return [4 /*yield*/, gtagOnEvent(gtagCore, initializationPromisesMap, dynamicConfigPromisesList,
|
|
353
|
+
return [4 /*yield*/, gtagOnEvent(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, measurementId, gtagParams)];
|
|
348
354
|
case 1:
|
|
349
355
|
// If EVENT, second arg must be measurementId.
|
|
350
356
|
_a.sent();
|
|
351
357
|
return [3 /*break*/, 5];
|
|
352
358
|
case 2:
|
|
353
359
|
if (!(command === "config" /* GtagCommand.CONFIG */)) return [3 /*break*/, 4];
|
|
360
|
+
measurementId = args[0], gtagParams = args[1];
|
|
354
361
|
// If CONFIG, second arg must be measurementId.
|
|
355
|
-
return [4 /*yield*/, gtagOnConfig(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, measurementIdToAppId,
|
|
362
|
+
return [4 /*yield*/, gtagOnConfig(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, measurementIdToAppId, measurementId, gtagParams)];
|
|
356
363
|
case 3:
|
|
357
364
|
// If CONFIG, second arg must be measurementId.
|
|
358
365
|
_a.sent();
|
|
359
366
|
return [3 /*break*/, 5];
|
|
360
367
|
case 4:
|
|
361
368
|
if (command === "consent" /* GtagCommand.CONSENT */) {
|
|
362
|
-
|
|
369
|
+
gtagParams = args[0];
|
|
363
370
|
gtagCore("consent" /* GtagCommand.CONSENT */, 'update', gtagParams);
|
|
364
371
|
}
|
|
365
|
-
else {
|
|
372
|
+
else if (command === "get" /* GtagCommand.GET */) {
|
|
373
|
+
measurementId = args[0], fieldName = args[1], callback = args[2];
|
|
374
|
+
gtagCore("get" /* GtagCommand.GET */, measurementId, fieldName, callback);
|
|
375
|
+
}
|
|
376
|
+
else if (command === "set" /* GtagCommand.SET */) {
|
|
377
|
+
customParams = args[0];
|
|
366
378
|
// If SET, second arg must be params.
|
|
367
|
-
gtagCore("set" /* GtagCommand.SET */,
|
|
379
|
+
gtagCore("set" /* GtagCommand.SET */, customParams);
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
gtagCore.apply(void 0, __spreadArray([command], args, false));
|
|
368
383
|
}
|
|
369
384
|
_a.label = 5;
|
|
370
385
|
case 5: return [3 /*break*/, 7];
|
|
@@ -843,6 +858,32 @@ function setUserProperties$1(gtagFunction, initializationPromise, properties, op
|
|
|
843
858
|
});
|
|
844
859
|
});
|
|
845
860
|
}
|
|
861
|
+
/**
|
|
862
|
+
* Retrieves a unique Google Analytics identifier for the web client.
|
|
863
|
+
* See {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/config#client_id | client_id}.
|
|
864
|
+
*
|
|
865
|
+
* @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
|
|
866
|
+
*/
|
|
867
|
+
function internalGetGoogleAnalyticsClientId(gtagFunction, initializationPromise) {
|
|
868
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
869
|
+
var measurementId;
|
|
870
|
+
return __generator(this, function (_a) {
|
|
871
|
+
switch (_a.label) {
|
|
872
|
+
case 0: return [4 /*yield*/, initializationPromise];
|
|
873
|
+
case 1:
|
|
874
|
+
measurementId = _a.sent();
|
|
875
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
876
|
+
gtagFunction("get" /* GtagCommand.GET */, measurementId, 'client_id', function (clientId) {
|
|
877
|
+
if (!clientId) {
|
|
878
|
+
reject(ERROR_FACTORY.create("no-client-id" /* AnalyticsError.NO_CLIENT_ID */));
|
|
879
|
+
}
|
|
880
|
+
resolve(clientId);
|
|
881
|
+
});
|
|
882
|
+
})];
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
});
|
|
886
|
+
}
|
|
846
887
|
/**
|
|
847
888
|
* Set whether collection is enabled for this ID.
|
|
848
889
|
*
|
|
@@ -1273,6 +1314,22 @@ function setCurrentScreen(analyticsInstance, screenName, options) {
|
|
|
1273
1314
|
analyticsInstance = getModularInstance(analyticsInstance);
|
|
1274
1315
|
setCurrentScreen$1(wrappedGtagFunction, initializationPromisesMap[analyticsInstance.app.options.appId], screenName, options).catch(function (e) { return logger.error(e); });
|
|
1275
1316
|
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Retrieves a unique Google Analytics identifier for the web client.
|
|
1319
|
+
* See {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/config#client_id | client_id}.
|
|
1320
|
+
*
|
|
1321
|
+
* @public
|
|
1322
|
+
*
|
|
1323
|
+
* @param app - The {@link @firebase/app#FirebaseApp} to use.
|
|
1324
|
+
*/
|
|
1325
|
+
function getGoogleAnalyticsClientId(analyticsInstance) {
|
|
1326
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1327
|
+
return __generator(this, function (_a) {
|
|
1328
|
+
analyticsInstance = getModularInstance(analyticsInstance);
|
|
1329
|
+
return [2 /*return*/, internalGetGoogleAnalyticsClientId(wrappedGtagFunction, initializationPromisesMap[analyticsInstance.app.options.appId])];
|
|
1330
|
+
});
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1276
1333
|
/**
|
|
1277
1334
|
* Use gtag `config` command to set `user_id`.
|
|
1278
1335
|
*
|
|
@@ -1358,7 +1415,7 @@ function setConsent(consentSettings) {
|
|
|
1358
1415
|
}
|
|
1359
1416
|
|
|
1360
1417
|
var name = "@firebase/analytics";
|
|
1361
|
-
var version = "0.
|
|
1418
|
+
var version = "0.10.0-canary.5a2ceb07b";
|
|
1362
1419
|
|
|
1363
1420
|
/**
|
|
1364
1421
|
* Firebase Analytics
|
|
@@ -1395,5 +1452,5 @@ function registerAnalytics() {
|
|
|
1395
1452
|
}
|
|
1396
1453
|
registerAnalytics();
|
|
1397
1454
|
|
|
1398
|
-
export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setConsent, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
|
|
1455
|
+
export { getAnalytics, getGoogleAnalyticsClientId, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setConsent, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
|
|
1399
1456
|
//# sourceMappingURL=index.esm.js.map
|