Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions web/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import {
getFunctions,
provideFunctions,
} from '@angular/fire/functions';
import {
getAnalytics,
provideAnalytics,
} from '@angular/fire/analytics';
import {
getRemoteConfig,
provideRemoteConfig,
Expand Down Expand Up @@ -83,6 +87,9 @@ import { environment } from 'environments/environment';
}
return functions;
}),
...(environment.firebase?.measurementId
? [provideAnalytics(() => getAnalytics())]
: []),
provideRemoteConfig(() => getRemoteConfig()),
provideStorage(() => {
const storage = getStorage();
Expand Down
30 changes: 30 additions & 0 deletions web/src/app/services/analytics/analytics.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2026 The Ground Authors.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Injectable, Optional } from '@angular/core';
import { Analytics, logEvent } from '@angular/fire/analytics';

@Injectable({
providedIn: 'root',
})
export class AnalyticsService {
constructor(@Optional() private analytics: Analytics) {}

logEvent(eventName: string, params?: Record<string, unknown>): void {
if (!this.analytics) return;
logEvent(this.analytics, eventName, params);
}
}
5 changes: 4 additions & 1 deletion web/src/app/services/survey/survey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Observable, firstValueFrom, of } from 'rxjs';

import { Role } from 'app/models/role.model';
import { DataSharingType, Survey, SurveyState } from 'app/models/survey.model';
import { AnalyticsService } from 'app/services/analytics/analytics.service';
import { AuthService } from 'app/services/auth/auth.service';
import { DataStoreService } from 'app/services/data-store/data-store.service';

Expand All @@ -29,7 +30,8 @@ import { DataStoreService } from 'app/services/data-store/data-store.service';
export class SurveyService {
constructor(
private dataStore: DataStoreService,
private authService: AuthService
private authService: AuthService,
private analyticsService: AnalyticsService
) {}

loadSurvey$(id: string): Observable<Survey> {
Expand Down Expand Up @@ -125,6 +127,7 @@ export class SurveyService {
description ?? '',
user
);
this.analyticsService.logEvent('survey_created');
return Promise.resolve(surveyId);
}

Expand Down
6 changes: 4 additions & 2 deletions web/src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
// `environment.test.ts`.
// The list of file replacements can be found in `angular.json`.

import { FirebaseOptions } from '@angular/fire/app';
import { Env } from 'environments/environment-enums';
import { Environment } from './environment-interface';

export const environment = {
export const environment: Environment = {
production: false,
googleMapsApiKey: '',
cloudFunctionsUrl: '',
Expand All @@ -34,5 +36,5 @@ export const environment = {
storageBucket: 'mock-storage-bucket',
messagingSenderId: 'mock-messaging-sender-id',
appId: 'mock-app-id',
},
} as FirebaseOptions,
};
Loading