Skip to content
6 changes: 6 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ module.exports = function (config) {
{ type: 'text-summary' }
]
},
files: [
{ pattern: 'src/assets/**/*', watched: false, included: false, served: true, nocache: false }
],
proxies: {
'/karma_webpack/assets/': '/base/src/assets/'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
Expand Down
9 changes: 7 additions & 2 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ describe('AppComponent', () => {
},
{
provide: TelemetryService,
useValue: jasmine.createSpyObj('TelemetryService', ['setTelemetry', 'telemetryStatus', 'telemetryEnabled'])
}
useValue: {
telemetryStatus: () => false,
telemetryEnabled: () => false,
fetchTelemetryStatus: () => Promise.resolve(false),
setTelemetry: () => Promise.resolve(false)
}
},
],
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { SnackbarService } from '../../core/services/snackbar.service';
import {Router} from '@angular/router';
// 1p-ONLY-IMPORTS: import {beforeEach, describe, expect, it}
import {initTestBed} from '../../testing/utils';
import {AnalyticsService} from '../../core/services/analytics.service';

describe('BuilderTabsComponent - Callback Support', () => {
let component: BuilderTabsComponent;
Expand Down Expand Up @@ -58,6 +59,7 @@ describe('BuilderTabsComponent - Callback Support', () => {
{provide: Router, useValue: mockRouter},
provideNoopAnimations(),
{provide: THEME_SERVICE, useClass: MockThemeService},
{provide: AnalyticsService, useValue: jasmine.createSpyObj('AnalyticsService', ['setUserProperties', 'sendEvent'])}
],
}).compileComponents();

Expand Down
3 changes: 3 additions & 0 deletions src/app/components/builder-tabs/builder-tabs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { MatIcon } from '@angular/material/icon';
import { MatInput } from '@angular/material/input';
import { MatOption, MatSelect } from '@angular/material/select';
import { SnackbarService } from '../../core/services/snackbar.service';
import { AnalyticsService } from '../../core/services/analytics.service';
import {MatExpansionModule} from '@angular/material/expansion';
import { MatTooltip } from '@angular/material/tooltip';
import { Router } from '@angular/router';
Expand Down Expand Up @@ -129,6 +130,7 @@ export class BuilderTabsComponent {
private snackBar = inject(SnackbarService);
private router = inject(Router);
private cdr = inject(ChangeDetectorRef);
private analyticsService = inject(AnalyticsService);

protected selectedTool: ToolNode | undefined = undefined;
protected toolAgentName: string = '';
Expand Down Expand Up @@ -802,6 +804,7 @@ export class BuilderTabsComponent {
if (success) {
this.agentService.agentBuild(appName, formData).subscribe((success) => {
if (success) {
this.analyticsService.sendEvent('builder_agent_save_click');
this.router.navigate(['/'], {
queryParams: { app: appName }
}).then(() => {
Expand Down
15 changes: 15 additions & 0 deletions src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { ListResponse } from '../../core/services/interfaces/types';
import { UI_STATE_SERVICE } from '../../core/services/interfaces/ui-state';
import { LOCATION_SERVICE } from '../../core/services/location.service';
import { TestsService } from '../../core/services/tests.service';
import { AnalyticsService } from '../../core/services/analytics.service';
import { ResizableDrawerDirective } from '../../directives/resizable-drawer.directive';
import { AddItemDialogComponent } from '../add-item-dialog/add-item-dialog.component';
import { AgentStructureGraphDialogComponent } from '../agent-structure-graph-dialog/agent-structure-graph-dialog';
Expand Down Expand Up @@ -221,6 +222,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
protected readonly agentBuilderService = inject(AGENT_BUILDER_SERVICE);
protected readonly themeService = inject(THEME_SERVICE, { optional: true });
protected readonly telemetryService = inject(TelemetryService);
protected readonly analyticsService = inject(AnalyticsService);
protected readonly logoComponent: Type<Component> | null = inject(LOGO_COMPONENT, {
optional: true,
});
Expand Down Expand Up @@ -553,6 +555,11 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
} catch (e) {
// Ignored
}
if (mode === 'events') {
this.analyticsService.sendEvent('event_view_toggle');
} else if (mode === 'traces') {
this.analyticsService.sendEvent('trace_view_toggle');
}
}
protected originalSessionId = '';
hideIntermediateEvents = signal(window.localStorage.getItem('adk-hide-intermediate-events') === 'true');
Expand Down Expand Up @@ -786,6 +793,10 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.agentService.getVersion().subscribe((res) => {
this.adkVersion.set(res.version || '');
this.versionInfo.set(res);
this.analyticsService.setUserProperties({
adk_version: res?.version || '',
adk_language: res?.language || '',
});
});

combineLatest([
Expand Down Expand Up @@ -1158,6 +1169,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.sessionId = res.id ?? '';
this.sessionTab?.refreshSession();
this.sessionTab?.reloadSession(this.sessionId);
this.analyticsService.sendEvent('chat_session_create');

this.isSessionUrlEnabledObs.subscribe((enabled) => {
if (enabled) {
Expand Down Expand Up @@ -1257,6 +1269,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
this.sessionService.createSession(this.userId, this.appName, initialState));
this.currentSessionState = res.state || initialState || {};
this.sessionId = res.id ?? '';
this.analyticsService.sendEvent('chat_session_create');
this.sessionTab?.refreshSession();
this.sessionTab?.reloadSession(this.sessionId);
this.drawerSessionTab()?.refreshSession();
Expand Down Expand Up @@ -3531,6 +3544,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
.toString();
this.location.replaceState(url);
this.isBuilderMode.set(true);
this.analyticsService.sendEvent('builder_enter_click');

// Load existing agent configuration if app is selected
if (this.appName) {
Expand Down Expand Up @@ -3592,6 +3606,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
openAgentStructureGraphDialog(mode: 'session' | 'event' = 'session'): void {
this.agentStructureOverlayMode = mode;
this.showAgentStructureOverlay = true;
this.analyticsService.sendEvent('graph_view_click');
}

saveAgentBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { EvalService } from '../../../../core/services/eval.service';
import { of } from 'rxjs';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {EVAL_SERVICE} from '../../../../core/services/interfaces/eval';
import {AnalyticsService} from '../../../../core/services/analytics.service';

describe('AddEvalSessionDialogComponent', () => {
let component: AddEvalSessionDialogComponent;
Expand All @@ -51,6 +52,7 @@ describe('AddEvalSessionDialogComponent', () => {
useValue: {},
},
{ provide: EVAL_SERVICE, useValue: evalService },
{provide: AnalyticsService, useValue: jasmine.createSpyObj('AnalyticsService', ['setUserProperties', 'sendEvent'])}
],
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef, MatDialogTitle, MatDialogContent, MatDialogActions, MatDialogClose } from '@angular/material/dialog';
import {uuidv4} from 'uuidv7';
import {EVAL_SERVICE} from '../../../../core/services/interfaces/eval';
import {AnalyticsService} from '../../../../core/services/analytics.service';
import { CdkScrollable } from '@angular/cdk/scrolling';
import { MatFormField } from '@angular/material/form-field';
import { MatInput } from '@angular/material/input';
Expand Down Expand Up @@ -55,6 +56,7 @@ export class AddEvalSessionDialogComponent {
existingCases?: string[];
} = inject(MAT_DIALOG_DATA);
readonly dialogRef = inject(MatDialogRef<AddEvalSessionDialogComponent>);
private readonly analyticsService = inject(AnalyticsService);

newCaseId: string = this.data.defaultName || ('case_' + uuidv4().slice(0, 6));
loading = false;
Expand All @@ -81,6 +83,7 @@ export class AddEvalSessionDialogComponent {
)
.subscribe({
next: (res) => {
this.analyticsService.sendEvent('eval_create_click');
this.dialogRef.close(true);
},
error: (err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { of } from 'rxjs';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {EVAL_SERVICE} from '../../../../core/services/interfaces/eval';
import {FEATURE_FLAG_SERVICE} from '../../../../core/services/interfaces/feature-flag';
import {AnalyticsService} from '../../../../core/services/analytics.service';

describe('NewEvalSetDialogComponentComponent', () => {
let component: NewEvalSetDialogComponentComponent;
Expand All @@ -53,6 +54,7 @@ describe('NewEvalSetDialogComponentComponent', () => {
{ provide: MAT_DIALOG_DATA, useValue: {} },
{ provide: EVAL_SERVICE, useValue: evalService },
{ provide: FEATURE_FLAG_SERVICE, useValue: featureFlagService },
{provide: AnalyticsService, useValue: jasmine.createSpyObj('AnalyticsService', ['setUserProperties', 'sendEvent'])}
],
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { FormsModule } from '@angular/forms';
import { MatButton } from '@angular/material/button';
import { MatSelectModule } from '@angular/material/select';

import {AnalyticsService} from '../../../../core/services/analytics.service';

@Component({
changeDetection: ChangeDetectionStrategy.Default,
selector: 'app-new-eval-set-dialog-component',
Expand All @@ -48,6 +50,7 @@ import { MatSelectModule } from '@angular/material/select';
export class NewEvalSetDialogComponentComponent {
private readonly evalService = inject(EVAL_SERVICE);
private readonly featureFlagService = inject(FEATURE_FLAG_SERVICE);
private readonly analyticsService = inject(AnalyticsService);
readonly data: {appName: string, defaultName?: string} = inject(MAT_DIALOG_DATA);
readonly dialogRef = inject(MatDialogRef<NewEvalSetDialogComponentComponent>);

Expand All @@ -69,6 +72,7 @@ export class NewEvalSetDialogComponentComponent {
this.evalService
.createNewEvalSet(this.data.appName, this.newSetId, executionMode)
.subscribe((res) => {
this.analyticsService.sendEvent('eval_create_click');
this.dialogRef.close(true);
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/side-panel/side-panel.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {VideoService} from '../../core/services/video.service';
import {WebSocketService} from '../../core/services/websocket.service';
import {initTestBed} from '../../testing/utils';
import {EVAL_TAB_COMPONENT, EvalTabComponent} from '../eval-tab/eval-tab.component';
import {AnalyticsService} from '../../core/services/analytics.service';

import {SidePanelComponent} from './side-panel.component';

Expand Down Expand Up @@ -202,7 +203,8 @@ describe('SidePanelComponent', () => {
{provide: ActivatedRoute, useValue: mockActivatedRoute},
{provide: Location, useValue: mockLocation},
{provide: SAFE_VALUES_SERVICE, useClass: MockSafeValuesService},
{provide: THEME_SERVICE, useClass: MockThemeService}
{provide: THEME_SERVICE, useClass: MockThemeService},
{provide: AnalyticsService, useValue: jasmine.createSpyObj('AnalyticsService', ['setUserProperties', 'sendEvent'])}
],
});

Expand Down
2 changes: 2 additions & 0 deletions src/app/components/side-panel/side-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {TraceTabComponent} from '../trace-tab/trace-tab.component';
import {EventTabComponent} from '../event-tab/event-tab.component';

import {TRACE_SERVICE} from '../../core/services/interfaces/trace';
import {AnalyticsService} from '../../core/services/analytics.service';
import {SidePanelMessagesInjectionToken} from './side-panel.component.i18n';

/**
Expand Down Expand Up @@ -119,6 +120,7 @@ export class SidePanelComponent implements AfterViewInit, OnInit {
viewChild('evalTabContainer', {read: ViewContainerRef});
readonly tabGroup = viewChild(MatTabGroup);

protected readonly analyticsService = inject(AnalyticsService);
readonly logoComponent: Type<Component>|null = inject(LOGO_COMPONENT, {
optional: true,
});
Expand Down
84 changes: 84 additions & 0 deletions src/app/core/services/analytics.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* @license
* Copyright 2026 Google LLC
*
* 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
*
* http://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 { TestBed } from '@angular/core/testing';
import { signal } from '@angular/core';
import { AnalyticsService, DEFAULT_GA_MEASUREMENT_ID } from './analytics.service';
import { TelemetryService } from './telemetry.service';

describe('AnalyticsService', () => {
let service: AnalyticsService;
let mockTelemetryService: {
telemetryEnabled: ReturnType<typeof signal<boolean>>;
};

beforeEach(() => {
mockTelemetryService = {
telemetryEnabled: signal(false),
};

TestBed.configureTestingModule({
providers: [
AnalyticsService,
{ provide: TelemetryService, useValue: mockTelemetryService },
],
});

// Mock window.gtag
window.gtag = jasmine.createSpy('gtag');

service = TestBed.inject(AnalyticsService);
(service as any).measurementId = 'G-TEST123456';
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('should NOT send events when telemetry consent is false', () => {
mockTelemetryService.telemetryEnabled.set(false);
service.sendEvent('test_event');
expect(window.gtag).not.toHaveBeenCalled();
});

it('should NOT set user properties when telemetry consent is false', () => {
mockTelemetryService.telemetryEnabled.set(false);
service.setUserProperties({ adk_version: '1.0.0' });
expect(window.gtag).not.toHaveBeenCalled();
});

it('should send events when telemetry consent is true', () => {
mockTelemetryService.telemetryEnabled.set(true);
service.sendEvent('chat_session_create');
expect(window.gtag).toHaveBeenCalledWith('event', 'chat_session_create');
});

it('should set user properties when telemetry consent is true', () => {
mockTelemetryService.telemetryEnabled.set(true);
service.setUserProperties({ adk_version: '1.0.0', adk_language: 'Python' });
expect(window.gtag).toHaveBeenCalledWith('set', 'user_properties', {
adk_version: '1.0.0',
adk_language: 'Python',
});
});

it('should disable analytics when telemetry consent becomes false', () => {
mockTelemetryService.telemetryEnabled.set(false);
TestBed.flushEffects();
expect(window['ga-disable-G-TEST123456']).toBeTrue();
});
});
Loading
Loading