Skip to content

Commit

Permalink
feat(analytics): Bunch of analytics & screen tracking improvements (#…
Browse files Browse the repository at this point in the history
…2654)

* Better handle lazy routes
* Better handle nested routes
* Better handle nested & lazy routes
* Handle multiple outlets correctly
* Handle multiple outlets that share the same lazy components (this was tricky)
* NO LONGER USING INTERNAL APIS OR REQUIRING ANNOTATIONS!!!! 🎉 😄 
* `APP_NAME` and `APP_VERSION` should be working now...
* `AngularFireAnalytics` now gets it's `measurementId` from Analytics rather than your config, there's an edge case where this can change out from underneath you, which the JS SDK handles
* Got `DEBUG_MODE` working again
  • Loading branch information
jamesdaniels committed Nov 14, 2020
1 parent d71b59f commit b00e14b
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 153 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,10 @@
<a name="6.1.0-rc.3"></a>
# [6.1.0-rc.3](https://github.com/angular/angularfire/compare/6.1.0-rc.2...6.1.0-rc.3) (2020-11-14)

### Bug Fixes

* **analytics:** Bunch of analytics & screen tracking improvements ([#2654](https://github.com/angular/angularfire/pull/2654)) ([5bc159a](https://github.com/angular/angularfire/commit/5bc159a))

<a name="6.1.0-rc.2"></a>
# [6.1.0-rc.2](https://github.com/angular/angularfire/compare/6.1.0-rc.1...6.1.0-rc.2) (2020-11-13)

Expand Down
18 changes: 16 additions & 2 deletions sample/src/app/app-routing.module.ts
@@ -1,10 +1,24 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';

import { ProtectedComponent } from './protected/protected.component';
import { AngularFireAuthGuard } from '@angular/fire/auth-guard';
import { SecondaryComponent } from './secondary/secondary.component';

const routes: Routes = [
{ path: '', component: HomeComponent, pathMatch: 'full' }
{ path: '', component: HomeComponent, outlet: 'primary' },
{ path: '', component: SecondaryComponent, outlet: 'secondary' },
{ path: '', component: SecondaryComponent, outlet: 'tertiary' },
{ path: 'protected', component: ProtectedComponent, canActivate: [AngularFireAuthGuard] },
{ path: 'protected-lazy',
loadChildren: () => import('./protected-lazy/protected-lazy.module').then(m => m.ProtectedLazyModule),
canActivate: [AngularFireAuthGuard] },
{ path: 'protected', component: ProtectedComponent, canActivate: [AngularFireAuthGuard], outlet: 'secondary' },
{ path: 'protected', component: ProtectedComponent, canActivate: [AngularFireAuthGuard], outlet: 'tertiary' },
{ path: 'protected-lazy',
loadChildren: () => import('./protected-lazy/protected-lazy.module').then(m => m.ProtectedLazyModule),
canActivate: [AngularFireAuthGuard],
outlet: 'secondary' },
];

@NgModule({
Expand Down
5 changes: 5 additions & 0 deletions sample/src/app/app.component.ts
Expand Up @@ -4,7 +4,12 @@ import { FirebaseApp } from '@angular/fire';
@Component({
selector: 'app-root',
template: `
<a [routerLink]="[{ outlets: { primary: [] }}]">Home</a> | <a [routerLink]="[{ outlets: { primary: ['protected'] }}]">Protected</a> | <a [routerLink]="[{ outlets: { primary: ['protected-lazy'] }}]">Protected Lazy</a> | <a [routerLink]="[{ outlets: { primary: ['protected-lazy', 'asdf'] }}]">Protected Lazy Deep</a> | <a [routerLink]="[{ outlets: { primary: ['protected-lazy', '1', 'bob'] }}]">Protected Lazy Deep</a>
<router-outlet></router-outlet>
<a [routerLink]="[{ outlets: { secondary: [] }}]">Home</a> | <a [routerLink]="[{ outlets: { secondary: ['protected'] }}]">Protected</a> | <a [routerLink]="[{ outlets: { secondary: ['protected-lazy'] }}]">Protected Lazy</a>
<router-outlet name="secondary"></router-outlet>
<a [routerLink]="[{ outlets: { tertiary: [] }}]">Home</a> | <a [routerLink]="[{ outlets: { tertiary: ['protected'] }}]">Protected</a>
<router-outlet name="tertiary"></router-outlet>
`,
styles: [``]
})
Expand Down
27 changes: 14 additions & 13 deletions sample/src/app/app.module.ts
Expand Up @@ -10,9 +10,12 @@ import { AngularFireModule } from '@angular/fire';

import {
AngularFireAnalyticsModule,
APP_NAME,
APP_VERSION,
DEBUG_MODE as ANALYTICS_DEBUG_MODE,
ScreenTrackingService,
UserTrackingService
UserTrackingService,
COLLECTION_ENABLED
} from '@angular/fire/analytics';

import { FirestoreComponent } from './firestore/firestore.component';
Expand Down Expand Up @@ -55,24 +58,20 @@ import { FunctionsComponent } from './functions/functions.component';
AngularFireDatabaseModule,
AngularFirestoreModule.enablePersistence({ synchronizeTabs: true }),
AngularFireAuthModule,
AngularFireAuthGuardModule,
AngularFireRemoteConfigModule,
AngularFireMessagingModule,
// AngularFireAnalyticsModule, // TODO having trouble getting this to work in IE
AngularFireAnalyticsModule,
AngularFireFunctionsModule,
// AngularFirePerformanceModule, // TODO having trouble getting this to work in IE
AngularFirePerformanceModule,
AngularFireAuthGuardModule
],
providers: [
/*
TODO Analytics and Performance monitoring aren't working in IE, sort this out
UserTrackingService,
ScreenTrackingService,
PerformanceMonitoringService,
{
provide: ANALYTICS_DEBUG_MODE,
useFactory: () => isDevMode()
},
*/
UserTrackingService,
ScreenTrackingService,
PerformanceMonitoringService,
{ provide: ANALYTICS_DEBUG_MODE, useValue: false },
{ provide: COLLECTION_ENABLED, useValue: true },
{ provide: USE_AUTH_EMULATOR, useValue: environment.useEmulators ? ['localhost', 9099] : undefined },
{ provide: USE_DATABASE_EMULATOR, useValue: environment.useEmulators ? ['localhost', 9000] : undefined },
{ provide: USE_FIRESTORE_EMULATOR, useValue: environment.useEmulators ? ['localhost', 8080] : undefined },
Expand All @@ -84,6 +83,8 @@ import { FunctionsComponent } from './functions/functions.component';
{ provide: USE_DEVICE_LANGUAGE, useValue: true },
{ provide: VAPID_KEY, useValue: environment.vapidKey },
{ provide: SERVICE_WORKER, useFactory: () => navigator?.serviceWorker?.getRegistration() ?? undefined },
{ provide: APP_VERSION, useValue: '0.0.0' },
{ provide: APP_NAME, useValue: 'Angular' }
],
bootstrap: [AppComponent]
})
Expand Down
16 changes: 16 additions & 0 deletions sample/src/app/protected-lazy/protected-lazy-routing.module.ts
@@ -0,0 +1,16 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { ProtectedLazyComponent } from './protected-lazy.component';

const routes: Routes = [
{ path: '', component: ProtectedLazyComponent },
{ path: 'asdf', component: ProtectedLazyComponent },
{ path: ':id/bob', component: ProtectedLazyComponent }
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class ProtectedLazyRoutingModule { }
Empty file.
@@ -0,0 +1 @@
<p>protected-lazy works!</p>
25 changes: 25 additions & 0 deletions sample/src/app/protected-lazy/protected-lazy.component.spec.ts
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ProtectedLazyComponent } from './protected-lazy.component';

describe('ProtectedLazyComponent', () => {
let component: ProtectedLazyComponent;
let fixture: ComponentFixture<ProtectedLazyComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProtectedLazyComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ProtectedLazyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions sample/src/app/protected-lazy/protected-lazy.component.ts
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-protected-lazy',
templateUrl: './protected-lazy.component.html',
styleUrls: ['./protected-lazy.component.css']
})
export class ProtectedLazyComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}
15 changes: 15 additions & 0 deletions sample/src/app/protected-lazy/protected-lazy.module.ts
@@ -0,0 +1,15 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { ProtectedLazyRoutingModule } from './protected-lazy-routing.module';
import { ProtectedLazyComponent } from './protected-lazy.component';


@NgModule({
declarations: [ProtectedLazyComponent],
imports: [
CommonModule,
ProtectedLazyRoutingModule
]
})
export class ProtectedLazyModule { }
Empty file.
1 change: 1 addition & 0 deletions sample/src/app/protected/protected.component.html
@@ -0,0 +1 @@
<p>protected works!</p>
25 changes: 25 additions & 0 deletions sample/src/app/protected/protected.component.spec.ts
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ProtectedComponent } from './protected.component';

describe('ProtectedComponent', () => {
let component: ProtectedComponent;
let fixture: ComponentFixture<ProtectedComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ProtectedComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ProtectedComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions sample/src/app/protected/protected.component.ts
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-protected',
templateUrl: './protected.component.html',
styleUrls: ['./protected.component.css']
})
export class ProtectedComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}
Empty file.
1 change: 1 addition & 0 deletions sample/src/app/secondary/secondary.component.html
@@ -0,0 +1 @@
<p>secondary works!</p>
25 changes: 25 additions & 0 deletions sample/src/app/secondary/secondary.component.spec.ts
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { SecondaryComponent } from './secondary.component';

describe('SecondaryComponent', () => {
let component: SecondaryComponent;
let fixture: ComponentFixture<SecondaryComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ SecondaryComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(SecondaryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions sample/src/app/secondary/secondary.component.ts
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-secondary',
templateUrl: './secondary.component.html',
styleUrls: ['./secondary.component.css']
})
export class SecondaryComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}

0 comments on commit b00e14b

Please sign in to comment.