@firebase/analytics 0.9.5 → 0.10.0-canary.9c317277f

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.
@@ -90,6 +90,7 @@ const ERRORS = {
90
90
  'contain a valid API key.',
91
91
  ["no-app-id" /* AnalyticsError.NO_APP_ID */]: 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
92
92
  'contain a valid app ID.',
93
+ ["no-client-id" /* AnalyticsError.NO_CLIENT_ID */]: 'The "client_id" field is empty.',
93
94
  ["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */]: 'Trusted Types detected an invalid gtag resource: {$gtagURL}.'
94
95
  };
95
96
  const ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
@@ -303,24 +304,34 @@ measurementIdToAppId) {
303
304
  * @param idOrNameOrParams Measurement ID if command is EVENT/CONFIG, params if command is SET.
304
305
  * @param gtagParams Params if event is EVENT/CONFIG.
305
306
  */
306
- async function gtagWrapper(command, idOrNameOrParams, gtagParams) {
307
+ async function gtagWrapper(command, ...args) {
307
308
  try {
308
309
  // If event, check that relevant initialization promises have completed.
309
310
  if (command === "event" /* GtagCommand.EVENT */) {
311
+ const [measurementId, gtagParams] = args;
310
312
  // If EVENT, second arg must be measurementId.
311
- await gtagOnEvent(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, idOrNameOrParams, gtagParams);
313
+ await gtagOnEvent(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, measurementId, gtagParams);
312
314
  }
313
315
  else if (command === "config" /* GtagCommand.CONFIG */) {
316
+ const [measurementId, gtagParams] = args;
314
317
  // If CONFIG, second arg must be measurementId.
315
- await gtagOnConfig(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, measurementIdToAppId, idOrNameOrParams, gtagParams);
318
+ await gtagOnConfig(gtagCore, initializationPromisesMap, dynamicConfigPromisesList, measurementIdToAppId, measurementId, gtagParams);
316
319
  }
317
320
  else if (command === "consent" /* GtagCommand.CONSENT */) {
318
- // If CONFIG, second arg must be measurementId.
321
+ const [gtagParams] = args;
319
322
  gtagCore("consent" /* GtagCommand.CONSENT */, 'update', gtagParams);
320
323
  }
321
- else {
324
+ else if (command === "get" /* GtagCommand.GET */) {
325
+ const [measurementId, fieldName, callback] = args;
326
+ gtagCore("get" /* GtagCommand.GET */, measurementId, fieldName, callback);
327
+ }
328
+ else if (command === "set" /* GtagCommand.SET */) {
329
+ const [customParams] = args;
322
330
  // If SET, second arg must be params.
323
- gtagCore("set" /* GtagCommand.SET */, idOrNameOrParams);
331
+ gtagCore("set" /* GtagCommand.SET */, customParams);
332
+ }
333
+ else {
334
+ gtagCore(command, ...args);
324
335
  }
325
336
  }
326
337
  catch (e) {
@@ -714,6 +725,23 @@ async function setUserProperties$1(gtagFunction, initializationPromise, properti
714
725
  });
715
726
  }
716
727
  }
728
+ /**
729
+ * Retrieves a unique Google Analytics identifier for the web client.
730
+ * See {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/config#client_id | client_id}.
731
+ *
732
+ * @param gtagFunction Wrapped gtag function that waits for fid to be set before sending an event
733
+ */
734
+ async function internalGetGoogleAnalyticsClientId(gtagFunction, initializationPromise) {
735
+ const measurementId = await initializationPromise;
736
+ return new Promise((resolve, reject) => {
737
+ gtagFunction("get" /* GtagCommand.GET */, measurementId, 'client_id', (clientId) => {
738
+ if (!clientId) {
739
+ reject(ERROR_FACTORY.create("no-client-id" /* AnalyticsError.NO_CLIENT_ID */));
740
+ }
741
+ resolve(clientId);
742
+ });
743
+ });
744
+ }
717
745
  /**
718
746
  * Set whether collection is enabled for this ID.
719
747
  *
@@ -1103,6 +1131,18 @@ function setCurrentScreen(analyticsInstance, screenName, options) {
1103
1131
  analyticsInstance = getModularInstance(analyticsInstance);
1104
1132
  setCurrentScreen$1(wrappedGtagFunction, initializationPromisesMap[analyticsInstance.app.options.appId], screenName, options).catch(e => logger.error(e));
1105
1133
  }
1134
+ /**
1135
+ * Retrieves a unique Google Analytics identifier for the web client.
1136
+ * See {@link https://developers.google.com/analytics/devguides/collection/ga4/reference/config#client_id | client_id}.
1137
+ *
1138
+ * @public
1139
+ *
1140
+ * @param app - The {@link @firebase/app#FirebaseApp} to use.
1141
+ */
1142
+ async function getGoogleAnalyticsClientId(analyticsInstance) {
1143
+ analyticsInstance = getModularInstance(analyticsInstance);
1144
+ return internalGetGoogleAnalyticsClientId(wrappedGtagFunction, initializationPromisesMap[analyticsInstance.app.options.appId]);
1145
+ }
1106
1146
  /**
1107
1147
  * Use gtag `config` command to set `user_id`.
1108
1148
  *
@@ -1188,7 +1228,7 @@ function setConsent(consentSettings) {
1188
1228
  }
1189
1229
 
1190
1230
  const name = "@firebase/analytics";
1191
- const version = "0.9.5";
1231
+ const version = "0.10.0-canary.9c317277f";
1192
1232
 
1193
1233
  /**
1194
1234
  * Firebase Analytics
@@ -1224,5 +1264,5 @@ function registerAnalytics() {
1224
1264
  }
1225
1265
  registerAnalytics();
1226
1266
 
1227
- export { getAnalytics, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setConsent, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1267
+ export { getAnalytics, getGoogleAnalyticsClientId, initializeAnalytics, isSupported, logEvent, setAnalyticsCollectionEnabled, setConsent, setCurrentScreen, setDefaultEventParameters, setUserId, setUserProperties, settings };
1228
1268
  //# sourceMappingURL=index.esm2017.js.map