MCPcopy
hub / github.com/angular/angularfire / constructor

Method constructor

src/compat/analytics/analytics.ts:45–158  ·  view source on GitHub ↗
(
    app: FirebaseApp,
    @Optional() @Inject(COLLECTION_ENABLED) analyticsCollectionEnabled: boolean | null,
    @Optional() @Inject(APP_VERSION) providedAppVersion: string | null,
    @Optional() @Inject(APP_NAME) providedAppName: string | null,
    @Optional() @Inject(DEBUG_MODE) debugModeEnabled: boolean | null,
    @Optional() @Inject(CONFIG) providedConfig: Config | null,
    // eslint-disable-next-line @typescript-eslint/ban-types
    @Inject(PLATFORM_ID) platformId: Object,
    zone: NgZone,
    schedulers: ɵAngularFireSchedulers,
  )

Source from the content-addressed store, hash-verified

43 }
44
45 constructor(
46 app: FirebaseApp,
47 @Optional() @Inject(COLLECTION_ENABLED) analyticsCollectionEnabled: boolean | null,
48 @Optional() @Inject(APP_VERSION) providedAppVersion: string | null,
49 @Optional() @Inject(APP_NAME) providedAppName: string | null,
50 @Optional() @Inject(DEBUG_MODE) debugModeEnabled: boolean | null,
51 @Optional() @Inject(CONFIG) providedConfig: Config | null,
52 // eslint-disable-next-line @typescript-eslint/ban-types
53 @Inject(PLATFORM_ID) platformId: Object,
54 zone: NgZone,
55 schedulers: ɵAngularFireSchedulers,
56 ) {
57
58 if (isPlatformBrowser(platformId)) {
59
60 window[DATA_LAYER_NAME] = window[DATA_LAYER_NAME] || [];
61
62 // It turns out we can't rely on the measurementId in the Firebase config JSON
63 // this identifier is not stable. firebase/analytics does a call to get a fresh value
64 // falling back on the one in the config. Rather than do that ourselves we should listen
65 // on our gtag function for a analytics config command
66 // e.g, ['config', measurementId, { origin: 'firebase', firebase_id }]
67 const parseMeasurementId = (...args: any[]) => {
68 if (args[0] === 'config' && args[2].origin === 'firebase') {
69 this.measurementId = args[1];
70 return true;
71 } else {
72 return false;
73 }
74 };
75
76 const patchGtag = (fn?: (...args: any[]) => void) => {
77 window[GTAG_FUNCTION_NAME] = (...args: any[]) => {
78 if (fn) {
79 fn(...args);
80 }
81 // Inject app_name and app_version into events
82 // TODO(jamesdaniels): I'm doing this as documented but it's still not
83 // showing up in the console. Investigate. Guessing it's just part of the
84 // whole GA4 transition mess.
85 if (args[0] === 'event' && args[2][SEND_TO_KEY] === this.measurementId) {
86 if (providedAppName) {
87 args[2][APP_NAME_KEY] = providedAppName;
88 }
89 if (providedAppVersion) {
90 args[2][APP_VERSION_KEY] = providedAppVersion;
91 }
92 }
93 if (debugModeEnabled && typeof console !== 'undefined') {
94 // eslint-disable-next-line no-console
95 console.info(...args);
96 }
97 /**
98 * According to the gtag documentation, this function that defines a custom data layer cannot be
99 * an arrow function because 'arguments' is not an array. It is actually an object that behaves
100 * like an array and contains more information then just indexes. Transforming this into arrow function
101 * caused issue #2505 where analytics no longer sent any data.
102 */

Callers

nothing calls this directly

Calls 3

updateConfigMethod · 0.95
ɵcacheInstanceFunction · 0.90
ɵlazySDKProxyFunction · 0.90

Tested by

no test coverage detected