UNPKG

34.2 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/fire'), require('rxjs'), require('rxjs/operators'), require('@angular/core'), require('@angular/fire/app'), require('firebase/app'), require('@angular/router'), require('firebase/analytics'), require('@angular/platform-browser'), require('@angular/fire/auth')) :
3 typeof define === 'function' && define.amd ? define('@angular/fire/analytics', ['exports', '@angular/fire', 'rxjs', 'rxjs/operators', '@angular/core', '@angular/fire/app', 'firebase/app', '@angular/router', 'firebase/analytics', '@angular/platform-browser', '@angular/fire/auth'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.angular = global.angular || {}, global.angular.fire = global.angular.fire || {}, global.angular.fire.analytics = {}), global.angular.fire, global.rxjs, global.rxjs.operators, global.ng.core, global.angular.fire.app, global.app, global.ng.router, global['firebase-analytics'], global.ng.platformBrowser, global.angular.fire.auth));
5}(this, (function (exports, fire, rxjs, operators, i0, app$1, app, i1$1, analytics, i2, i1) { 'use strict';
6
7 function _interopNamespace(e) {
8 if (e && e.__esModule) return e;
9 var n = Object.create(null);
10 if (e) {
11 Object.keys(e).forEach(function (k) {
12 if (k !== 'default') {
13 var d = Object.getOwnPropertyDescriptor(e, k);
14 Object.defineProperty(n, k, d.get ? d : {
15 enumerable: true,
16 get: function () {
17 return e[k];
18 }
19 });
20 }
21 });
22 }
23 n['default'] = e;
24 return Object.freeze(n);
25 }
26
27 var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28 var i1__namespace$1 = /*#__PURE__*/_interopNamespace(i1$1);
29 var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
30 var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
31
32 var Analytics = /** @class */ (function () {
33 function Analytics(analytics) {
34 return analytics;
35 }
36 return Analytics;
37 }());
38 var ANALYTICS_PROVIDER_NAME = 'analytics';
39 var AnalyticsInstances = /** @class */ (function () {
40 function AnalyticsInstances() {
41 return fire.ɵgetAllInstancesOf(ANALYTICS_PROVIDER_NAME);
42 }
43 return AnalyticsInstances;
44 }());
45 var analyticInstance$ = rxjs.timer(0, 300).pipe(operators.concatMap(function () { return rxjs.from(fire.ɵgetAllInstancesOf(ANALYTICS_PROVIDER_NAME)); }), operators.distinct());
46
47 /*! *****************************************************************************
48 Copyright (c) Microsoft Corporation.
49
50 Permission to use, copy, modify, and/or distribute this software for any
51 purpose with or without fee is hereby granted.
52
53 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
54 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
55 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
56 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
57 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
58 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
59 PERFORMANCE OF THIS SOFTWARE.
60 ***************************************************************************** */
61 /* global Reflect, Promise */
62 var extendStatics = function (d, b) {
63 extendStatics = Object.setPrototypeOf ||
64 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
65 function (d, b) { for (var p in b)
66 if (Object.prototype.hasOwnProperty.call(b, p))
67 d[p] = b[p]; };
68 return extendStatics(d, b);
69 };
70 function __extends(d, b) {
71 if (typeof b !== "function" && b !== null)
72 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
73 extendStatics(d, b);
74 function __() { this.constructor = d; }
75 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
76 }
77 var __assign = function () {
78 __assign = Object.assign || function __assign(t) {
79 for (var s, i = 1, n = arguments.length; i < n; i++) {
80 s = arguments[i];
81 for (var p in s)
82 if (Object.prototype.hasOwnProperty.call(s, p))
83 t[p] = s[p];
84 }
85 return t;
86 };
87 return __assign.apply(this, arguments);
88 };
89 function __rest(s, e) {
90 var t = {};
91 for (var p in s)
92 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
93 t[p] = s[p];
94 if (s != null && typeof Object.getOwnPropertySymbols === "function")
95 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
96 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
97 t[p[i]] = s[p[i]];
98 }
99 return t;
100 }
101 function __decorate(decorators, target, key, desc) {
102 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
103 if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
104 r = Reflect.decorate(decorators, target, key, desc);
105 else
106 for (var i = decorators.length - 1; i >= 0; i--)
107 if (d = decorators[i])
108 r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
109 return c > 3 && r && Object.defineProperty(target, key, r), r;
110 }
111 function __param(paramIndex, decorator) {
112 return function (target, key) { decorator(target, key, paramIndex); };
113 }
114 function __metadata(metadataKey, metadataValue) {
115 if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
116 return Reflect.metadata(metadataKey, metadataValue);
117 }
118 function __awaiter(thisArg, _arguments, P, generator) {
119 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
120 return new (P || (P = Promise))(function (resolve, reject) {
121 function fulfilled(value) { try {
122 step(generator.next(value));
123 }
124 catch (e) {
125 reject(e);
126 } }
127 function rejected(value) { try {
128 step(generator["throw"](value));
129 }
130 catch (e) {
131 reject(e);
132 } }
133 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
134 step((generator = generator.apply(thisArg, _arguments || [])).next());
135 });
136 }
137 function __generator(thisArg, body) {
138 var _ = { label: 0, sent: function () { if (t[0] & 1)
139 throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
140 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
141 function verb(n) { return function (v) { return step([n, v]); }; }
142 function step(op) {
143 if (f)
144 throw new TypeError("Generator is already executing.");
145 while (_)
146 try {
147 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)
148 return t;
149 if (y = 0, t)
150 op = [op[0] & 2, t.value];
151 switch (op[0]) {
152 case 0:
153 case 1:
154 t = op;
155 break;
156 case 4:
157 _.label++;
158 return { value: op[1], done: false };
159 case 5:
160 _.label++;
161 y = op[1];
162 op = [0];
163 continue;
164 case 7:
165 op = _.ops.pop();
166 _.trys.pop();
167 continue;
168 default:
169 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
170 _ = 0;
171 continue;
172 }
173 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
174 _.label = op[1];
175 break;
176 }
177 if (op[0] === 6 && _.label < t[1]) {
178 _.label = t[1];
179 t = op;
180 break;
181 }
182 if (t && _.label < t[2]) {
183 _.label = t[2];
184 _.ops.push(op);
185 break;
186 }
187 if (t[2])
188 _.ops.pop();
189 _.trys.pop();
190 continue;
191 }
192 op = body.call(thisArg, _);
193 }
194 catch (e) {
195 op = [6, e];
196 y = 0;
197 }
198 finally {
199 f = t = 0;
200 }
201 if (op[0] & 5)
202 throw op[1];
203 return { value: op[0] ? op[1] : void 0, done: true };
204 }
205 }
206 var __createBinding = Object.create ? (function (o, m, k, k2) {
207 if (k2 === undefined)
208 k2 = k;
209 Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
210 }) : (function (o, m, k, k2) {
211 if (k2 === undefined)
212 k2 = k;
213 o[k2] = m[k];
214 });
215 function __exportStar(m, o) {
216 for (var p in m)
217 if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
218 __createBinding(o, m, p);
219 }
220 function __values(o) {
221 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
222 if (m)
223 return m.call(o);
224 if (o && typeof o.length === "number")
225 return {
226 next: function () {
227 if (o && i >= o.length)
228 o = void 0;
229 return { value: o && o[i++], done: !o };
230 }
231 };
232 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
233 }
234 function __read(o, n) {
235 var m = typeof Symbol === "function" && o[Symbol.iterator];
236 if (!m)
237 return o;
238 var i = m.call(o), r, ar = [], e;
239 try {
240 while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
241 ar.push(r.value);
242 }
243 catch (error) {
244 e = { error: error };
245 }
246 finally {
247 try {
248 if (r && !r.done && (m = i["return"]))
249 m.call(i);
250 }
251 finally {
252 if (e)
253 throw e.error;
254 }
255 }
256 return ar;
257 }
258 /** @deprecated */
259 function __spread() {
260 for (var ar = [], i = 0; i < arguments.length; i++)
261 ar = ar.concat(__read(arguments[i]));
262 return ar;
263 }
264 /** @deprecated */
265 function __spreadArrays() {
266 for (var s = 0, i = 0, il = arguments.length; i < il; i++)
267 s += arguments[i].length;
268 for (var r = Array(s), k = 0, i = 0; i < il; i++)
269 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
270 r[k] = a[j];
271 return r;
272 }
273 function __spreadArray(to, from) {
274 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
275 to[j] = from[i];
276 return to;
277 }
278 function __await(v) {
279 return this instanceof __await ? (this.v = v, this) : new __await(v);
280 }
281 function __asyncGenerator(thisArg, _arguments, generator) {
282 if (!Symbol.asyncIterator)
283 throw new TypeError("Symbol.asyncIterator is not defined.");
284 var g = generator.apply(thisArg, _arguments || []), i, q = [];
285 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
286 function verb(n) { if (g[n])
287 i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
288 function resume(n, v) { try {
289 step(g[n](v));
290 }
291 catch (e) {
292 settle(q[0][3], e);
293 } }
294 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
295 function fulfill(value) { resume("next", value); }
296 function reject(value) { resume("throw", value); }
297 function settle(f, v) { if (f(v), q.shift(), q.length)
298 resume(q[0][0], q[0][1]); }
299 }
300 function __asyncDelegator(o) {
301 var i, p;
302 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
303 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; }
304 }
305 function __asyncValues(o) {
306 if (!Symbol.asyncIterator)
307 throw new TypeError("Symbol.asyncIterator is not defined.");
308 var m = o[Symbol.asyncIterator], i;
309 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);
310 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); }); }; }
311 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
312 }
313 function __makeTemplateObject(cooked, raw) {
314 if (Object.defineProperty) {
315 Object.defineProperty(cooked, "raw", { value: raw });
316 }
317 else {
318 cooked.raw = raw;
319 }
320 return cooked;
321 }
322 ;
323 var __setModuleDefault = Object.create ? (function (o, v) {
324 Object.defineProperty(o, "default", { enumerable: true, value: v });
325 }) : function (o, v) {
326 o["default"] = v;
327 };
328 function __importStar(mod) {
329 if (mod && mod.__esModule)
330 return mod;
331 var result = {};
332 if (mod != null)
333 for (var k in mod)
334 if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
335 __createBinding(result, mod, k);
336 __setModuleDefault(result, mod);
337 return result;
338 }
339 function __importDefault(mod) {
340 return (mod && mod.__esModule) ? mod : { default: mod };
341 }
342 function __classPrivateFieldGet(receiver, state, kind, f) {
343 if (kind === "a" && !f)
344 throw new TypeError("Private accessor was defined without a getter");
345 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
346 throw new TypeError("Cannot read private member from an object whose class did not declare it");
347 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
348 }
349 function __classPrivateFieldSet(receiver, state, value, kind, f) {
350 if (kind === "m")
351 throw new TypeError("Private method is not writable");
352 if (kind === "a" && !f)
353 throw new TypeError("Private accessor was defined without a setter");
354 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
355 throw new TypeError("Cannot write private member to an object whose class did not declare it");
356 return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
357 }
358
359 var isSupported = fire.ɵisAnalyticsSupportedFactory.async;
360
361 // DO NOT MODIFY, this file is autogenerated by tools/build.ts
362 var getAnalytics = fire.ɵzoneWrap(analytics.getAnalytics, true);
363 var initializeAnalytics = fire.ɵzoneWrap(analytics.initializeAnalytics, true);
364 var logEvent = fire.ɵzoneWrap(analytics.logEvent, true);
365 var setAnalyticsCollectionEnabled = fire.ɵzoneWrap(analytics.setAnalyticsCollectionEnabled, true);
366 var setCurrentScreen = fire.ɵzoneWrap(analytics.setCurrentScreen, true);
367 var settings = fire.ɵzoneWrap(analytics.settings, true);
368 var setUserId = fire.ɵzoneWrap(analytics.setUserId, true);
369 var setUserProperties = fire.ɵzoneWrap(analytics.setUserProperties, true);
370
371 var UserTrackingService = /** @class */ (function () {
372 function UserTrackingService(auth, zone, injector) {
373 var _this = this;
374 this.disposables = [];
375 app.registerVersion('angularfire', fire.VERSION.full, 'user-tracking');
376 var resolveInitialized;
377 this.initialized = zone.runOutsideAngular(function () { return new Promise(function (resolve) { resolveInitialized = resolve; }); });
378 // The APP_INITIALIZER that is making isSupported() sync for the sake of convenient DI
379 // may not be done when services are initialized. Guard the functionality by first ensuring
380 // that the (global) promise has resolved, then get Analytics from the injector.
381 isSupported().then(function () {
382 var analytics = injector.get(Analytics);
383 if (analytics) {
384 _this.disposables = [
385 // TODO add credential tracking back in
386 i1.authState(auth).subscribe(function (user) {
387 setUserId(analytics, user === null || user === void 0 ? void 0 : user.uid);
388 resolveInitialized();
389 }),
390 ];
391 }
392 else {
393 resolveInitialized();
394 }
395 });
396 }
397 UserTrackingService.prototype.ngOnDestroy = function () {
398 this.disposables.forEach(function (it) { return it.unsubscribe(); });
399 };
400 return UserTrackingService;
401 }());
402 UserTrackingService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: UserTrackingService, deps: [{ token: i1__namespace.Auth }, { token: i0__namespace.NgZone }, { token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
403 UserTrackingService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: UserTrackingService });
404 i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: UserTrackingService, decorators: [{
405 type: i0.Injectable
406 }], ctorParameters: function () { return [{ type: i1__namespace.Auth }, { type: i0__namespace.NgZone }, { type: i0__namespace.Injector }]; } });
407
408 var FIREBASE_EVENT_ORIGIN_KEY = 'firebase_event_origin';
409 var FIREBASE_PREVIOUS_SCREEN_CLASS_KEY = 'firebase_previous_class';
410 var FIREBASE_PREVIOUS_SCREEN_INSTANCE_ID_KEY = 'firebase_previous_id';
411 var FIREBASE_PREVIOUS_SCREEN_NAME_KEY = 'firebase_previous_screen';
412 var FIREBASE_SCREEN_CLASS_KEY = 'firebase_screen_class';
413 var FIREBASE_SCREEN_INSTANCE_ID_KEY = 'firebase_screen_id';
414 var FIREBASE_SCREEN_NAME_KEY = 'firebase_screen';
415 var OUTLET_KEY = 'outlet';
416 var PAGE_PATH_KEY = 'page_path';
417 var PAGE_TITLE_KEY = 'page_title';
418 var SCREEN_CLASS_KEY = 'screen_class';
419 var SCREEN_NAME_KEY = 'screen_name';
420 var SCREEN_VIEW_EVENT = 'screen_view';
421 var EVENT_ORIGIN_AUTO = 'auto';
422 var SCREEN_INSTANCE_DELIMITER = '#';
423 // this is an INT64 in iOS/Android but use INT32 cause javascript
424 var nextScreenInstanceID = Math.floor(Math.random() * (Math.pow(2, 32) - 1)) - Math.pow(2, 31);
425 var knownScreenInstanceIDs = {};
426 var getScreenInstanceID = function (params) {
427 // unique the screen class against the outlet name
428 var screenInstanceKey = [
429 params[SCREEN_CLASS_KEY],
430 params[OUTLET_KEY]
431 ].join(SCREEN_INSTANCE_DELIMITER);
432 if (knownScreenInstanceIDs.hasOwnProperty(screenInstanceKey)) {
433 return knownScreenInstanceIDs[screenInstanceKey];
434 }
435 else {
436 var ret = nextScreenInstanceID++;
437 knownScreenInstanceIDs[screenInstanceKey] = ret;
438 return ret;
439 }
440 };
441 var ɵscreenViewEvent = function (router, title, componentFactoryResolver) {
442 var activationEndEvents = router.events.pipe(operators.filter(function (e) { return e instanceof i1$1.ActivationEnd; }));
443 return activationEndEvents.pipe(operators.switchMap(function (activationEnd) {
444 var _b, _c, _d;
445 var _a;
446 // router parseUrl is having trouble with outlets when they're empty
447 // e.g, /asdf/1(bob://sally:asdf), so put another slash in when empty
448 var urlTree = router.parseUrl(router.url.replace(/(?:\().+(?:\))/g, function (a) { return a.replace('://', ':///'); }));
449 var pagePath = ((_a = urlTree.root.children[activationEnd.snapshot.outlet]) === null || _a === void 0 ? void 0 : _a.toString()) || '';
450 var actualSnapshot = router.routerState.root.children.map(function (it) { return it; }).find(function (it) { return it.outlet === activationEnd.snapshot.outlet; });
451 if (!actualSnapshot) {
452 return rxjs.of(null);
453 }
454 var actualDeep = actualSnapshot;
455 while (actualDeep.firstChild) {
456 actualDeep = actualDeep.firstChild;
457 }
458 var screenName = actualDeep.pathFromRoot.map(function (s) { var _a; return (_a = s.routeConfig) === null || _a === void 0 ? void 0 : _a.path; }).filter(function (it) { return it; }).join('/') || '/';
459 var params = (_b = {},
460 _b[SCREEN_NAME_KEY] = screenName,
461 _b[PAGE_PATH_KEY] = "/" + pagePath,
462 _b[FIREBASE_EVENT_ORIGIN_KEY] = EVENT_ORIGIN_AUTO,
463 _b[FIREBASE_SCREEN_NAME_KEY] = screenName,
464 _b[OUTLET_KEY] = activationEnd.snapshot.outlet,
465 _b);
466 if (title) {
467 params[PAGE_TITLE_KEY] = title.getTitle();
468 }
469 var component = actualSnapshot.component;
470 if (component) {
471 if (component === i1$1.ɵEmptyOutletComponent) {
472 var deepSnapshot = activationEnd.snapshot;
473 // TODO when might there be mutple children, different outlets? explore
474 while (deepSnapshot.firstChild) {
475 deepSnapshot = deepSnapshot.firstChild;
476 }
477 component = deepSnapshot.component;
478 }
479 }
480 else {
481 component = activationEnd.snapshot.component;
482 }
483 if (typeof component === 'string') {
484 return rxjs.of(Object.assign(Object.assign({}, params), (_c = {}, _c[SCREEN_CLASS_KEY] = component, _c)));
485 }
486 else if (component) {
487 var componentFactory = componentFactoryResolver.resolveComponentFactory(component);
488 return rxjs.of(Object.assign(Object.assign({}, params), (_d = {}, _d[SCREEN_CLASS_KEY] = componentFactory.selector, _d)));
489 }
490 // lazy loads cause extra activations, ignore
491 return rxjs.of(null);
492 }), operators.filter(function (it) { return !!it; }), operators.map(function (params) {
493 var _b;
494 return (Object.assign((_b = {}, _b[FIREBASE_SCREEN_CLASS_KEY] = params[SCREEN_CLASS_KEY], _b[FIREBASE_SCREEN_INSTANCE_ID_KEY] = getScreenInstanceID(params), _b), params));
495 }), operators.groupBy(function (it) { return it[OUTLET_KEY]; }), operators.mergeMap(function (it) { return it.pipe(operators.distinctUntilChanged(function (a, b) { return JSON.stringify(a) === JSON.stringify(b); }), operators.startWith(undefined), operators.pairwise(), operators.map(function (_b) {
496 var _c;
497 var _d = __read(_b, 2), prior = _d[0], current = _d[1];
498 return prior ? Object.assign((_c = {}, _c[FIREBASE_PREVIOUS_SCREEN_CLASS_KEY] = prior[SCREEN_CLASS_KEY], _c[FIREBASE_PREVIOUS_SCREEN_NAME_KEY] = prior[SCREEN_NAME_KEY], _c[FIREBASE_PREVIOUS_SCREEN_INSTANCE_ID_KEY] = prior[FIREBASE_SCREEN_INSTANCE_ID_KEY], _c), current) : current;
499 })); }));
500 };
501 var ScreenTrackingService = /** @class */ (function () {
502 function ScreenTrackingService(router, title, componentFactoryResolver, zone, userTrackingService, injector) {
503 var _this = this;
504 app.registerVersion('angularfire', fire.VERSION.full, 'screen-tracking');
505 // The APP_INITIALIZER that is making isSupported() sync for the sake of convenient DI
506 // may not be done when services are initialized. Guard the functionality by first ensuring
507 // that the (global) promise has resolved, then get Analytics from the injector.
508 isSupported().then(function () {
509 var analytics = injector.get(Analytics);
510 if (!router || !analytics) {
511 return;
512 }
513 zone.runOutsideAngular(function () {
514 _this.disposable = ɵscreenViewEvent(router, title, componentFactoryResolver).pipe(operators.switchMap(function (params) { return __awaiter(_this, void 0, void 0, function () {
515 return __generator(this, function (_b) {
516 switch (_b.label) {
517 case 0:
518 if (!userTrackingService) return [3 /*break*/, 2];
519 return [4 /*yield*/, userTrackingService.initialized];
520 case 1:
521 _b.sent();
522 _b.label = 2;
523 case 2: return [2 /*return*/, logEvent(analytics, SCREEN_VIEW_EVENT, params)];
524 }
525 });
526 }); })).subscribe();
527 });
528 });
529 }
530 ScreenTrackingService.prototype.ngOnDestroy = function () {
531 if (this.disposable) {
532 this.disposable.unsubscribe();
533 }
534 };
535 return ScreenTrackingService;
536 }());
537 ScreenTrackingService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ScreenTrackingService, deps: [{ token: i1__namespace$1.Router, optional: true }, { token: i2__namespace.Title, optional: true }, { token: i0__namespace.ComponentFactoryResolver }, { token: i0__namespace.NgZone }, { token: UserTrackingService, optional: true }, { token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
538 ScreenTrackingService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ScreenTrackingService });
539 i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ScreenTrackingService, decorators: [{
540 type: i0.Injectable
541 }], ctorParameters: function () {
542 return [{ type: i1__namespace$1.Router, decorators: [{
543 type: i0.Optional
544 }] }, { type: i2__namespace.Title, decorators: [{
545 type: i0.Optional
546 }] }, { type: i0__namespace.ComponentFactoryResolver }, { type: i0__namespace.NgZone }, { type: UserTrackingService, decorators: [{
547 type: i0.Optional
548 }] }, { type: i0__namespace.Injector }];
549 } });
550
551 var PROVIDED_ANALYTICS_INSTANCES = new i0.InjectionToken('angularfire2.analytics-instances');
552 function defaultAnalyticsInstanceFactory(provided, defaultApp) {
553 if (!fire.ɵisAnalyticsSupportedFactory.sync()) {
554 return null;
555 }
556 var defaultAnalytics = fire.ɵgetDefaultInstanceOf(ANALYTICS_PROVIDER_NAME, provided, defaultApp);
557 return defaultAnalytics && new Analytics(defaultAnalytics);
558 }
559 function analyticsInstanceFactory(fn) {
560 return function (zone, injector) {
561 if (!fire.ɵisAnalyticsSupportedFactory.sync()) {
562 return null;
563 }
564 var analytics = zone.runOutsideAngular(function () { return fn(injector); });
565 return new Analytics(analytics);
566 };
567 }
568 var ANALYTICS_INSTANCES_PROVIDER = {
569 provide: AnalyticsInstances,
570 deps: [
571 [new i0.Optional(), PROVIDED_ANALYTICS_INSTANCES],
572 ]
573 };
574 var DEFAULT_ANALYTICS_INSTANCE_PROVIDER = {
575 provide: Analytics,
576 useFactory: defaultAnalyticsInstanceFactory,
577 deps: [
578 [new i0.Optional(), PROVIDED_ANALYTICS_INSTANCES],
579 app$1.FirebaseApp,
580 ]
581 };
582 var AnalyticsModule = /** @class */ (function () {
583 function AnalyticsModule(_screenTrackingService, _userTrackingService) {
584 app.registerVersion('angularfire', fire.VERSION.full, 'analytics');
585 }
586 return AnalyticsModule;
587 }());
588 AnalyticsModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AnalyticsModule, deps: [{ token: ScreenTrackingService, optional: true }, { token: UserTrackingService, optional: true }], target: i0__namespace.ɵɵFactoryTarget.NgModule });
589 AnalyticsModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AnalyticsModule });
590 AnalyticsModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AnalyticsModule, providers: [
591 DEFAULT_ANALYTICS_INSTANCE_PROVIDER,
592 ANALYTICS_INSTANCES_PROVIDER,
593 {
594 provide: i0.APP_INITIALIZER,
595 useValue: fire.ɵisAnalyticsSupportedFactory.async,
596 multi: true,
597 }
598 ] });
599 i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AnalyticsModule, decorators: [{
600 type: i0.NgModule,
601 args: [{
602 providers: [
603 DEFAULT_ANALYTICS_INSTANCE_PROVIDER,
604 ANALYTICS_INSTANCES_PROVIDER,
605 {
606 provide: i0.APP_INITIALIZER,
607 useValue: fire.ɵisAnalyticsSupportedFactory.async,
608 multi: true,
609 }
610 ]
611 }]
612 }], ctorParameters: function () {
613 return [{ type: ScreenTrackingService, decorators: [{
614 type: i0.Optional
615 }] }, { type: UserTrackingService, decorators: [{
616 type: i0.Optional
617 }] }];
618 } });
619 function provideAnalytics(fn) {
620 var deps = [];
621 for (var _i = 1; _i < arguments.length; _i++) {
622 deps[_i - 1] = arguments[_i];
623 }
624 return {
625 ngModule: AnalyticsModule,
626 providers: [{
627 provide: PROVIDED_ANALYTICS_INSTANCES,
628 useFactory: analyticsInstanceFactory(fn),
629 multi: true,
630 deps: __spreadArray([
631 i0.NgZone,
632 i0.Injector,
633 fire.ɵAngularFireSchedulers,
634 app$1.FirebaseApps
635 ], __read(deps))
636 }]
637 };
638 }
639
640 /**
641 * Generated bundle index. Do not edit.
642 */
643
644 exports.Analytics = Analytics;
645 exports.AnalyticsInstances = AnalyticsInstances;
646 exports.AnalyticsModule = AnalyticsModule;
647 exports.ScreenTrackingService = ScreenTrackingService;
648 exports.UserTrackingService = UserTrackingService;
649 exports.analyticInstance$ = analyticInstance$;
650 exports.getAnalytics = getAnalytics;
651 exports.initializeAnalytics = initializeAnalytics;
652 exports.isSupported = isSupported;
653 exports.logEvent = logEvent;
654 exports.provideAnalytics = provideAnalytics;
655 exports.setAnalyticsCollectionEnabled = setAnalyticsCollectionEnabled;
656 exports.setCurrentScreen = setCurrentScreen;
657 exports.setUserId = setUserId;
658 exports.setUserProperties = setUserProperties;
659 exports.settings = settings;
660 exports.ɵscreenViewEvent = ɵscreenViewEvent;
661 Object.keys(analytics).forEach(function (k) {
662 if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
663 enumerable: true,
664 get: function () {
665 return analytics[k];
666 }
667 });
668 });
669
670 Object.defineProperty(exports, '__esModule', { value: true });
671
672})));
673//# sourceMappingURL=angular-fire-analytics.umd.js.map