Skip to content

Commit 73413e8

Browse files
committed
DI and jazz
1 parent f5f67ad commit 73413e8

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/analytics/analytics.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Router, NavigationEnd, ActivationEnd } from '@angular/router';
66
import { FirebaseAnalytics, FIREBASE_OPTIONS, FIREBASE_APP_NAME, _firebaseAppFactory } from '@angular/fire';
77

88
export const AUTOMATICALLY_SET_CURRENT_SCREEN = new InjectionToken<boolean>('angularfire2.analytics.setCurrentScreen');
9+
export const AUTOMATICALLY_LOG_SCREEN_VIEWS = new InjectionToken<boolean>('angularfire2.analytics.logScreenViews');
910
export const ANALYTICS_COLLECTION_ENABLED = new InjectionToken<boolean>('angularfire2.analytics.analyticsCollectionEnabled');
1011
export const AUTOMATICALLY_TRACK_USER_IDENTIFIER = new InjectionToken<boolean>('angularfire2.analytics.trackUserIdentifier');
1112
export const APP_VERSION = new InjectionToken<string>('angularfire2.analytics.appVersion');
@@ -27,6 +28,7 @@ export class AngularFireAnalytics {
2728
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig:string|FirebaseAppConfig|null|undefined,
2829
@Optional() router:Router,
2930
@Optional() @Inject(AUTOMATICALLY_SET_CURRENT_SCREEN) automaticallySetCurrentScreen:boolean|null,
31+
@Optional() @Inject(AUTOMATICALLY_LOG_SCREEN_VIEWS) automaticallyLogScreenViews:boolean|null,
3032
@Optional() @Inject(ANALYTICS_COLLECTION_ENABLED) analyticsCollectionEnabled:boolean|null,
3133
@Optional() @Inject(AUTOMATICALLY_TRACK_USER_IDENTIFIER) automaticallyTrackUserIdentifier:boolean|null,
3234
@Optional() @Inject(APP_VERSION) providedAppVersion:string|null,
@@ -45,7 +47,7 @@ export class AngularFireAnalytics {
4547
runOutsideAngular(zone)
4648
);
4749

48-
if (router && automaticallySetCurrentScreen !== false) {
50+
if (router && (automaticallySetCurrentScreen !== false || automaticallyLogScreenViews !== false)) {
4951
const app_name = providedAppName || DEFAULT_APP_NAME;
5052
const app_version = providedAppVersion || DEFAULT_APP_VERSION;
5153
const activationEndEvents = router.events.pipe(filter<ActivationEnd>(e => e instanceof ActivationEnd));
@@ -56,9 +58,13 @@ export class AngularFireAnalytics {
5658
const url = navigationEnd.url;
5759
const screen_name = activationEnd.snapshot.routeConfig && activationEnd.snapshot.routeConfig.path || undefined;
5860
const outlet = activationEnd.snapshot.outlet;
59-
analytics.logEvent("screen_view", { app_name, app_version, screen_name, outlet, url });
60-
// TODO when is screen_name undefined?
61-
analytics.setCurrentScreen(screen_name || url, { global: outlet == "primary" })
61+
if (automaticallyLogScreenViews !== false) {
62+
analytics.logEvent("screen_view", { app_name, app_version, screen_name, outlet, url });
63+
}
64+
if (automaticallySetCurrentScreen !== false) {
65+
// TODO when is screen_name undefined?
66+
analytics.setCurrentScreen(screen_name || url, { global: outlet == "primary" })
67+
}
6268
}),
6369
runOutsideAngular(zone)
6470
).subscribe();

src/remote-config/remote-config.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable, Inject, Optional, NgZone, InjectionToken } from '@angular/core';
2-
import { Observable, from } from 'rxjs';
3-
import { map, switchMap, tap } from 'rxjs/operators';
2+
import { Observable, from, concat } from 'rxjs';
3+
import { map, switchMap, tap, take } from 'rxjs/operators';
44
import { FirebaseAppConfig, FirebaseOptions, FIREBASE_OPTIONS, FIREBASE_APP_NAME } from '@angular/fire';
55
import { remoteConfig } from 'firebase/app';
66

@@ -26,6 +26,8 @@ export class AngularFireRemoteConfig {
2626

2727
public readonly configuration: Observable<{[key:string]: remoteConfig.Value}>;
2828

29+
public readonly activate: Observable<{[key:string]: remoteConfig.Value}>;
30+
2931
constructor(
3032
@Inject(FIREBASE_OPTIONS) options:FirebaseOptions,
3133
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig:string|FirebaseAppConfig|null|undefined,
@@ -50,15 +52,25 @@ export class AngularFireRemoteConfig {
5052
runOutsideAngular(zone)
5153
);
5254

55+
this.activate = this.remoteConfig.pipe(
56+
switchMap(rc => rc.activate().then(() => rc)),
57+
tap(rc => rc.fetch()),
58+
map(rc => rc.getAll()),
59+
runOutsideAngular(zone),
60+
take(1)
61+
)
62+
5363
this.freshConfiguration = this.remoteConfig.pipe(
5464
switchMap(rc => rc.fetchAndActivate().then(() => rc.getAll())),
55-
runOutsideAngular(zone)
65+
runOutsideAngular(zone),
66+
take(1)
5667
)
5768

5869
this.configuration = this.remoteConfig.pipe(
59-
switchMap(rc => rc.activate().then(() => rc)),
60-
tap(rc => rc.fetch()),
61-
map(rc => rc.getAll()),
70+
switchMap(rc => concat(
71+
rc.activate().then(() => rc.getAll()),
72+
rc.fetchAndActivate().then(() => rc.getAll())
73+
)),
6274
runOutsideAngular(zone)
6375
)
6476
}

0 commit comments

Comments
 (0)