UNPKG

36.2 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('@angular/common'), require('rxjs/operators'), require('@angular/fire/compat'), require('firebase/analytics'), require('@angular/fire'), require('firebase/compat/app'), require('@angular/fire/analytics'), require('@angular/router'), require('@angular/platform-browser'), require('@angular/fire/compat/auth')) :
3 typeof define === 'function' && define.amd ? define('@angular/fire/compat/analytics', ['exports', '@angular/core', 'rxjs', '@angular/common', 'rxjs/operators', '@angular/fire/compat', 'firebase/analytics', '@angular/fire', 'firebase/compat/app', '@angular/fire/analytics', '@angular/router', '@angular/platform-browser', '@angular/fire/compat/auth'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.angular = global.angular || {}, global.angular.fire = global.angular.fire || {}, global.angular.fire.compat = global.angular.fire.compat || {}, global.angular.fire.compat.analytics = {}), global.ng.core, global.rxjs, global.ng.common, global.rxjs.operators, global.angular.fire.compat, global.analytics, global.angular.fire, global.firebase, global.angular.fire.analytics, global.ng.router, global.ng.platformBrowser, global.angular.fire.compat.auth));
5}(this, (function (exports, i0, rxjs, common, operators, i1, analytics, i2, firebase, analytics$1, i2$2, i3, i2$1) { 'use strict';
6
7 function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
9 function _interopNamespace(e) {
10 if (e && e.__esModule) return e;
11 var n = Object.create(null);
12 if (e) {
13 Object.keys(e).forEach(function (k) {
14 if (k !== 'default') {
15 var d = Object.getOwnPropertyDescriptor(e, k);
16 Object.defineProperty(n, k, d.get ? d : {
17 enumerable: true,
18 get: function () {
19 return e[k];
20 }
21 });
22 }
23 });
24 }
25 n['default'] = e;
26 return Object.freeze(n);
27 }
28
29 var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
30 var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
31 var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
32 var firebase__default = /*#__PURE__*/_interopDefaultLegacy(firebase);
33 var i2__namespace$2 = /*#__PURE__*/_interopNamespace(i2$2);
34 var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
35 var i2__namespace$1 = /*#__PURE__*/_interopNamespace(i2$1);
36
37 /*! *****************************************************************************
38 Copyright (c) Microsoft Corporation.
39
40 Permission to use, copy, modify, and/or distribute this software for any
41 purpose with or without fee is hereby granted.
42
43 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
44 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
45 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
46 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
47 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
48 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
49 PERFORMANCE OF THIS SOFTWARE.
50 ***************************************************************************** */
51 /* global Reflect, Promise */
52 var extendStatics = function (d, b) {
53 extendStatics = Object.setPrototypeOf ||
54 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
55 function (d, b) { for (var p in b)
56 if (Object.prototype.hasOwnProperty.call(b, p))
57 d[p] = b[p]; };
58 return extendStatics(d, b);
59 };
60 function __extends(d, b) {
61 if (typeof b !== "function" && b !== null)
62 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
63 extendStatics(d, b);
64 function __() { this.constructor = d; }
65 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
66 }
67 var __assign = function () {
68 __assign = Object.assign || function __assign(t) {
69 for (var s, i = 1, n = arguments.length; i < n; i++) {
70 s = arguments[i];
71 for (var p in s)
72 if (Object.prototype.hasOwnProperty.call(s, p))
73 t[p] = s[p];
74 }
75 return t;
76 };
77 return __assign.apply(this, arguments);
78 };
79 function __rest(s, e) {
80 var t = {};
81 for (var p in s)
82 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
83 t[p] = s[p];
84 if (s != null && typeof Object.getOwnPropertySymbols === "function")
85 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
86 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
87 t[p[i]] = s[p[i]];
88 }
89 return t;
90 }
91 function __decorate(decorators, target, key, desc) {
92 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
93 if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
94 r = Reflect.decorate(decorators, target, key, desc);
95 else
96 for (var i = decorators.length - 1; i >= 0; i--)
97 if (d = decorators[i])
98 r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
99 return c > 3 && r && Object.defineProperty(target, key, r), r;
100 }
101 function __param(paramIndex, decorator) {
102 return function (target, key) { decorator(target, key, paramIndex); };
103 }
104 function __metadata(metadataKey, metadataValue) {
105 if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
106 return Reflect.metadata(metadataKey, metadataValue);
107 }
108 function __awaiter(thisArg, _arguments, P, generator) {
109 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
110 return new (P || (P = Promise))(function (resolve, reject) {
111 function fulfilled(value) { try {
112 step(generator.next(value));
113 }
114 catch (e) {
115 reject(e);
116 } }
117 function rejected(value) { try {
118 step(generator["throw"](value));
119 }
120 catch (e) {
121 reject(e);
122 } }
123 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
124 step((generator = generator.apply(thisArg, _arguments || [])).next());
125 });
126 }
127 function __generator(thisArg, body) {
128 var _ = { label: 0, sent: function () { if (t[0] & 1)
129 throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
130 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
131 function verb(n) { return function (v) { return step([n, v]); }; }
132 function step(op) {
133 if (f)
134 throw new TypeError("Generator is already executing.");
135 while (_)
136 try {
137 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
138 return t;
139 if (y = 0, t)
140 op = [op[0] & 2, t.value];
141 switch (op[0]) {
142 case 0:
143 case 1:
144 t = op;
145 break;
146 case 4:
147 _.label++;
148 return { value: op[1], done: false };
149 case 5:
150 _.label++;
151 y = op[1];
152 op = [0];
153 continue;
154 case 7:
155 op = _.ops.pop();
156 _.trys.pop();
157 continue;
158 default:
159 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
160 _ = 0;
161 continue;
162 }
163 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
164 _.label = op[1];
165 break;
166 }
167 if (op[0] === 6 && _.label < t[1]) {
168 _.label = t[1];
169 t = op;
170 break;
171 }
172 if (t && _.label < t[2]) {
173 _.label = t[2];
174 _.ops.push(op);
175 break;
176 }
177 if (t[2])
178 _.ops.pop();
179 _.trys.pop();
180 continue;
181 }
182 op = body.call(thisArg, _);
183 }
184 catch (e) {
185 op = [6, e];
186 y = 0;
187 }
188 finally {
189 f = t = 0;
190 }
191 if (op[0] & 5)
192 throw op[1];
193 return { value: op[0] ? op[1] : void 0, done: true };
194 }
195 }
196 var __createBinding = Object.create ? (function (o, m, k, k2) {
197 if (k2 === undefined)
198 k2 = k;
199 Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
200 }) : (function (o, m, k, k2) {
201 if (k2 === undefined)
202 k2 = k;
203 o[k2] = m[k];
204 });
205 function __exportStar(m, o) {
206 for (var p in m)
207 if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
208 __createBinding(o, m, p);
209 }
210 function __values(o) {
211 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
212 if (m)
213 return m.call(o);
214 if (o && typeof o.length === "number")
215 return {
216 next: function () {
217 if (o && i >= o.length)
218 o = void 0;
219 return { value: o && o[i++], done: !o };
220 }
221 };
222 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
223 }
224 function __read(o, n) {
225 var m = typeof Symbol === "function" && o[Symbol.iterator];
226 if (!m)
227 return o;
228 var i = m.call(o), r, ar = [], e;
229 try {
230 while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
231 ar.push(r.value);
232 }
233 catch (error) {
234 e = { error: error };
235 }
236 finally {
237 try {
238 if (r && !r.done && (m = i["return"]))
239 m.call(i);
240 }
241 finally {
242 if (e)
243 throw e.error;
244 }
245 }
246 return ar;
247 }
248 /** @deprecated */
249 function __spread() {
250 for (var ar = [], i = 0; i < arguments.length; i++)
251 ar = ar.concat(__read(arguments[i]));
252 return ar;
253 }
254 /** @deprecated */
255 function __spreadArrays() {
256 for (var s = 0, i = 0, il = arguments.length; i < il; i++)
257 s += arguments[i].length;
258 for (var r = Array(s), k = 0, i = 0; i < il; i++)
259 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
260 r[k] = a[j];
261 return r;
262 }
263 function __spreadArray(to, from) {
264 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
265 to[j] = from[i];
266 return to;
267 }
268 function __await(v) {
269 return this instanceof __await ? (this.v = v, this) : new __await(v);
270 }
271 function __asyncGenerator(thisArg, _arguments, generator) {
272 if (!Symbol.asyncIterator)
273 throw new TypeError("Symbol.asyncIterator is not defined.");
274 var g = generator.apply(thisArg, _arguments || []), i, q = [];
275 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
276 function verb(n) { if (g[n])
277 i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
278 function resume(n, v) { try {
279 step(g[n](v));
280 }
281 catch (e) {
282 settle(q[0][3], e);
283 } }
284 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
285 function fulfill(value) { resume("next", value); }
286 function reject(value) { resume("throw", value); }
287 function settle(f, v) { if (f(v), q.shift(), q.length)
288 resume(q[0][0], q[0][1]); }
289 }
290 function __asyncDelegator(o) {
291 var i, p;
292 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
293 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
294 }
295 function __asyncValues(o) {
296 if (!Symbol.asyncIterator)
297 throw new TypeError("Symbol.asyncIterator is not defined.");
298 var m = o[Symbol.asyncIterator], i;
299 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
300 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
301 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
302 }
303 function __makeTemplateObject(cooked, raw) {
304 if (Object.defineProperty) {
305 Object.defineProperty(cooked, "raw", { value: raw });
306 }
307 else {
308 cooked.raw = raw;
309 }
310 return cooked;
311 }
312 ;
313 var __setModuleDefault = Object.create ? (function (o, v) {
314 Object.defineProperty(o, "default", { enumerable: true, value: v });
315 }) : function (o, v) {
316 o["default"] = v;
317 };
318 function __importStar(mod) {
319 if (mod && mod.__esModule)
320 return mod;
321 var result = {};
322 if (mod != null)
323 for (var k in mod)
324 if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
325 __createBinding(result, mod, k);
326 __setModuleDefault(result, mod);
327 return result;
328 }
329 function __importDefault(mod) {
330 return (mod && mod.__esModule) ? mod : { default: mod };
331 }
332 function __classPrivateFieldGet(receiver, state, kind, f) {
333 if (kind === "a" && !f)
334 throw new TypeError("Private accessor was defined without a getter");
335 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
336 throw new TypeError("Cannot read private member from an object whose class did not declare it");
337 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
338 }
339 function __classPrivateFieldSet(receiver, state, value, kind, f) {
340 if (kind === "m")
341 throw new TypeError("Private method is not writable");
342 if (kind === "a" && !f)
343 throw new TypeError("Private accessor was defined without a setter");
344 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
345 throw new TypeError("Cannot write private member to an object whose class did not declare it");
346 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
347 }
348
349 // DO NOT MODIFY, this file is autogenerated by tools/build.ts
350 // Export a null object with the same keys as firebase/compat/analytics, so Proxy can work with proxy-polyfill in Internet Explorer
351 var proxyPolyfillCompat = {
352 app: null,
353 logEvent: null,
354 setCurrentScreen: null,
355 setUserId: null,
356 setUserProperties: null,
357 setAnalyticsCollectionEnabled: null,
358 };
359
360 var COLLECTION_ENABLED = new i0.InjectionToken('angularfire2.analytics.analyticsCollectionEnabled');
361 var APP_VERSION = new i0.InjectionToken('angularfire2.analytics.appVersion');
362 var APP_NAME = new i0.InjectionToken('angularfire2.analytics.appName');
363 var DEBUG_MODE = new i0.InjectionToken('angularfire2.analytics.debugMode');
364 var CONFIG = new i0.InjectionToken('angularfire2.analytics.config');
365 var APP_NAME_KEY = 'app_name';
366 var APP_VERSION_KEY = 'app_version';
367 var DEBUG_MODE_KEY = 'debug_mode';
368 var GTAG_CONFIG_COMMAND = 'config';
369 var GTAG_FUNCTION_NAME = 'gtag'; // TODO rename these
370 var DATA_LAYER_NAME = 'dataLayer';
371 var SEND_TO_KEY = 'send_to';
372 var AngularFireAnalytics = /** @class */ (function () {
373 function AngularFireAnalytics(app, analyticsCollectionEnabled, providedAppVersion, providedAppName, debugModeEnabled, providedConfig,
374 // tslint:disable-next-line:ban-types
375 platformId, zone, schedulers) {
376 var _a;
377 var _this = this;
378 this.analyticsInitialized = new Promise(function () { });
379 if (common.isPlatformBrowser(platformId)) {
380 window[DATA_LAYER_NAME] = window[DATA_LAYER_NAME] || [];
381 // It turns out we can't rely on the measurementId in the Firebase config JSON
382 // this identifier is not stable. firebase/analytics does a call to get a fresh value
383 // falling back on the one in the config. Rather than do that ourselves we should listen
384 // on our gtag function for a analytics config command
385 // e.g, ['config', measurementId, { origin: 'firebase', firebase_id }]
386 var parseMeasurementId_1 = function () {
387 var args = [];
388 for (var _i = 0; _i < arguments.length; _i++) {
389 args[_i] = arguments[_i];
390 }
391 if (args[0] === 'config' && args[2].origin === 'firebase') {
392 _this.measurementId = args[1];
393 return true;
394 }
395 else {
396 return false;
397 }
398 };
399 var patchGtag_1 = function (fn) {
400 window[GTAG_FUNCTION_NAME] = function () {
401 var args = [];
402 for (var _i = 0; _i < arguments.length; _i++) {
403 args[_i] = arguments[_i];
404 }
405 if (fn) {
406 fn.apply(void 0, __spreadArray([], __read(args)));
407 }
408 // Inject app_name and app_version into events
409 // TODO(jamesdaniels): I'm doing this as documented but it's still not
410 // showing up in the console. Investigate. Guessing it's just part of the
411 // whole GA4 transition mess.
412 if (args[0] === 'event' && args[2][SEND_TO_KEY] === _this.measurementId) {
413 if (providedAppName) {
414 args[2][APP_NAME_KEY] = providedAppName;
415 }
416 if (providedAppVersion) {
417 args[2][APP_VERSION_KEY] = providedAppVersion;
418 }
419 }
420 if (debugModeEnabled && typeof console !== 'undefined') {
421 // tslint:disable-next-line:no-console
422 console.info.apply(console, __spreadArray([], __read(args)));
423 }
424 /**
425 * According to the gtag documentation, this function that defines a custom data layer cannot be
426 * an arrow function because 'arguments' is not an array. It is actually an object that behaves
427 * like an array and contains more information then just indexes. Transforming this into arrow function
428 * caused issue #2505 where analytics no longer sent any data.
429 */
430 // tslint:disable-next-line: only-arrow-functions
431 (function () {
432 var _args = [];
433 for (var _i = 0; _i < arguments.length; _i++) {
434 _args[_i] = arguments[_i];
435 }
436 window[DATA_LAYER_NAME].push(arguments);
437 }).apply(void 0, __spreadArray([], __read(args)));
438 };
439 };
440 // Unclear if we still need to but I was running into config/events I passed
441 // to gtag before ['js' timestamp] weren't getting parsed, so let's make a promise
442 // that resolves when firebase/analytics has configured gtag.js that we wait on
443 // before sending anything
444 var firebaseAnalyticsAlreadyInitialized = window[DATA_LAYER_NAME].some(parseMeasurementId_1);
445 if (firebaseAnalyticsAlreadyInitialized) {
446 this.analyticsInitialized = Promise.resolve();
447 patchGtag_1();
448 }
449 else {
450 this.analyticsInitialized = new Promise(function (resolve) {
451 patchGtag_1(function () {
452 var args = [];
453 for (var _i = 0; _i < arguments.length; _i++) {
454 args[_i] = arguments[_i];
455 }
456 if (parseMeasurementId_1.apply(void 0, __spreadArray([], __read(args)))) {
457 resolve();
458 }
459 });
460 });
461 }
462 if (providedConfig) {
463 this.updateConfig(providedConfig);
464 }
465 if (debugModeEnabled) {
466 this.updateConfig((_a = {}, _a[DEBUG_MODE_KEY] = 1, _a));
467 }
468 }
469 else {
470 this.analyticsInitialized = Promise.resolve();
471 }
472 var analytics$1 = rxjs.of(undefined).pipe(operators.observeOn(schedulers.outsideAngular), operators.switchMap(analytics.isSupported), operators.switchMap(function (supported) { return supported ? zone.runOutsideAngular(function () { return rxjs.of(undefined); }) : rxjs.EMPTY; }), operators.map(function () {
473 return i1.ɵcacheInstance("analytics", 'AngularFireAnalytics', app.name, function () {
474 var analytics = app.analytics();
475 if (analyticsCollectionEnabled === false) {
476 analytics.setAnalyticsCollectionEnabled(false);
477 }
478 return analytics;
479 }, [app, analyticsCollectionEnabled, providedConfig, debugModeEnabled]);
480 }), operators.shareReplay({ bufferSize: 1, refCount: false }));
481 return i1.ɵlazySDKProxy(this, analytics$1, zone);
482 }
483 AngularFireAnalytics.prototype.updateConfig = function (config) {
484 return __awaiter(this, void 0, void 0, function () {
485 return __generator(this, function (_a) {
486 switch (_a.label) {
487 case 0: return [4 /*yield*/, this.analyticsInitialized];
488 case 1:
489 _a.sent();
490 window[GTAG_FUNCTION_NAME](GTAG_CONFIG_COMMAND, this.measurementId, Object.assign(Object.assign({}, config), { update: true }));
491 return [2 /*return*/];
492 }
493 });
494 });
495 };
496 return AngularFireAnalytics;
497 }());
498 AngularFireAnalytics.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AngularFireAnalytics, deps: [{ token: i1__namespace.FirebaseApp }, { token: COLLECTION_ENABLED, optional: true }, { token: APP_VERSION, optional: true }, { token: APP_NAME, optional: true }, { token: DEBUG_MODE, optional: true }, { token: CONFIG, optional: true }, { token: i0.PLATFORM_ID }, { token: i0__namespace.NgZone }, { token: i2__namespace.ɵAngularFireSchedulers }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
499 AngularFireAnalytics.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AngularFireAnalytics, providedIn: 'any' });
500 i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AngularFireAnalytics, decorators: [{
501 type: i0.Injectable,
502 args: [{
503 providedIn: 'any'
504 }]
505 }], ctorParameters: function () {
506 return [{ type: i1__namespace.FirebaseApp }, { type: undefined, decorators: [{
507 type: i0.Optional
508 }, {
509 type: i0.Inject,
510 args: [COLLECTION_ENABLED]
511 }] }, { type: undefined, decorators: [{
512 type: i0.Optional
513 }, {
514 type: i0.Inject,
515 args: [APP_VERSION]
516 }] }, { type: undefined, decorators: [{
517 type: i0.Optional
518 }, {
519 type: i0.Inject,
520 args: [APP_NAME]
521 }] }, { type: undefined, decorators: [{
522 type: i0.Optional
523 }, {
524 type: i0.Inject,
525 args: [DEBUG_MODE]
526 }] }, { type: undefined, decorators: [{
527 type: i0.Optional
528 }, {
529 type: i0.Inject,
530 args: [CONFIG]
531 }] }, { type: Object, decorators: [{
532 type: i0.Inject,
533 args: [i0.PLATFORM_ID]
534 }] }, { type: i0__namespace.NgZone }, { type: i2__namespace.ɵAngularFireSchedulers }];
535 } });
536 i1.ɵapplyMixins(AngularFireAnalytics, [proxyPolyfillCompat]);
537
538 var UserTrackingService = /** @class */ (function () {
539 // TODO a user properties injector
540 function UserTrackingService(analytics,
541 // tslint:disable-next-line:ban-types
542 platformId, auth, zone) {
543 this.disposables = [];
544 firebase__default['default'].registerVersion('angularfire', i2.VERSION.full, 'compat-user-tracking');
545 if (!common.isPlatformServer(platformId)) {
546 var resolveInitialized_1;
547 this.initialized = zone.runOutsideAngular(function () { return new Promise(function (resolve) { return resolveInitialized_1 = resolve; }); });
548 this.disposables = [
549 auth.authState.subscribe(function (user) {
550 analytics.setUserId(user === null || user === void 0 ? void 0 : user.uid);
551 resolveInitialized_1();
552 }),
553 auth.credential.subscribe(function (credential) {
554 if (credential) {
555 var method = credential.user.isAnonymous ? 'anonymous' : credential.additionalUserInfo.providerId;
556 if (credential.additionalUserInfo.isNewUser) {
557 analytics.logEvent('sign_up', { method: method });
558 }
559 analytics.logEvent('login', { method: method });
560 }
561 })
562 ];
563 }
564 else {
565 this.initialized = Promise.resolve();
566 }
567 }
568 UserTrackingService.prototype.ngOnDestroy = function () {
569 this.disposables.forEach(function (it) { return it.unsubscribe(); });
570 };
571 return UserTrackingService;
572 }());
573 UserTrackingService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: UserTrackingService, deps: [{ token: AngularFireAnalytics }, { token: i0.PLATFORM_ID }, { token: i2__namespace$1.AngularFireAuth }, { token: i0__namespace.NgZone }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
574 UserTrackingService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: UserTrackingService });
575 i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: UserTrackingService, decorators: [{
576 type: i0.Injectable
577 }], ctorParameters: function () {
578 return [{ type: AngularFireAnalytics }, { type: Object, decorators: [{
579 type: i0.Inject,
580 args: [i0.PLATFORM_ID]
581 }] }, { type: i2__namespace$1.AngularFireAuth }, { type: i0__namespace.NgZone }];
582 } });
583
584 var SCREEN_VIEW_EVENT = 'screen_view';
585 var ScreenTrackingService = /** @class */ (function () {
586 function ScreenTrackingService(analytics, router, title, componentFactoryResolver, zone, userTrackingService) {
587 var _this = this;
588 firebase__default['default'].registerVersion('angularfire', i2.VERSION.full, 'compat-screen-tracking');
589 if (!router || !analytics) {
590 return this;
591 }
592 zone.runOutsideAngular(function () {
593 _this.disposable = analytics$1.ɵscreenViewEvent(router, title, componentFactoryResolver).pipe(operators.switchMap(function (params) { return __awaiter(_this, void 0, void 0, function () {
594 return __generator(this, function (_a) {
595 switch (_a.label) {
596 case 0:
597 if (!userTrackingService) return [3 /*break*/, 2];
598 return [4 /*yield*/, userTrackingService.initialized];
599 case 1:
600 _a.sent();
601 _a.label = 2;
602 case 2: return [4 /*yield*/, analytics.logEvent(SCREEN_VIEW_EVENT, params)];
603 case 3: return [2 /*return*/, _a.sent()];
604 }
605 });
606 }); })).subscribe();
607 });
608 }
609 ScreenTrackingService.prototype.ngOnDestroy = function () {
610 if (this.disposable) {
611 this.disposable.unsubscribe();
612 }
613 };
614 return ScreenTrackingService;
615 }());
616 ScreenTrackingService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ScreenTrackingService, deps: [{ token: AngularFireAnalytics }, { token: i2__namespace$2.Router, optional: true }, { token: i3__namespace.Title, optional: true }, { token: i0__namespace.ComponentFactoryResolver }, { token: i0__namespace.NgZone }, { token: UserTrackingService, optional: true }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
617 ScreenTrackingService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ScreenTrackingService });
618 i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ScreenTrackingService, decorators: [{
619 type: i0.Injectable
620 }], ctorParameters: function () {
621 return [{ type: AngularFireAnalytics }, { type: i2__namespace$2.Router, decorators: [{
622 type: i0.Optional
623 }] }, { type: i3__namespace.Title, decorators: [{
624 type: i0.Optional
625 }] }, { type: i0__namespace.ComponentFactoryResolver }, { type: i0__namespace.NgZone }, { type: UserTrackingService, decorators: [{
626 type: i0.Optional
627 }] }];
628 } });
629
630 var AngularFireAnalyticsModule = /** @class */ (function () {
631 function AngularFireAnalyticsModule(analytics, screenTracking, userTracking) {
632 firebase__default['default'].registerVersion('angularfire', i2.VERSION.full, 'analytics-compat');
633 // calling anything on analytics will eagerly load the SDK
634 // tslint:disable-next-line:no-unused-expression
635 analytics.app.then(function () { });
636 }
637 return AngularFireAnalyticsModule;
638 }());
639 AngularFireAnalyticsModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AngularFireAnalyticsModule, deps: [{ token: AngularFireAnalytics }, { token: ScreenTrackingService, optional: true }, { token: UserTrackingService, optional: true }], target: i0__namespace.ɵɵFactoryTarget.NgModule });
640 AngularFireAnalyticsModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AngularFireAnalyticsModule });
641 AngularFireAnalyticsModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AngularFireAnalyticsModule, providers: [AngularFireAnalytics] });
642 i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AngularFireAnalyticsModule, decorators: [{
643 type: i0.NgModule,
644 args: [{
645 providers: [AngularFireAnalytics]
646 }]
647 }], ctorParameters: function () {
648 return [{ type: AngularFireAnalytics }, { type: ScreenTrackingService, decorators: [{
649 type: i0.Optional
650 }] }, { type: UserTrackingService, decorators: [{
651 type: i0.Optional
652 }] }];
653 } });
654
655 /**
656 * Generated bundle index. Do not edit.
657 */
658
659 exports.APP_NAME = APP_NAME;
660 exports.APP_VERSION = APP_VERSION;
661 exports.AngularFireAnalytics = AngularFireAnalytics;
662 exports.AngularFireAnalyticsModule = AngularFireAnalyticsModule;
663 exports.COLLECTION_ENABLED = COLLECTION_ENABLED;
664 exports.CONFIG = CONFIG;
665 exports.DEBUG_MODE = DEBUG_MODE;
666 exports.ScreenTrackingService = ScreenTrackingService;
667 exports.UserTrackingService = UserTrackingService;
668
669 Object.defineProperty(exports, '__esModule', { value: true });
670
671})));
672//# sourceMappingURL=angular-fire-compat-analytics.umd.js.map