Skip to content

Commit

Permalink
Add Analytics Preparation
Browse files Browse the repository at this point in the history
Add Analytics Preparation
  • Loading branch information
SebastianStehle authored Aug 11, 2023
1 parent 331d3c2 commit 9e772cc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions frontend/src/app/framework/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './angular/drag-helper';
export * from './angular/routers/router-utils';
export * from './angular/stateful.component';
export * from './configurations';
export * from './services/analytics.service';
export * from './services/clipboard.service';
export * from './services/dialog.service';
export * from './services/loading.service';
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/app/framework/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import { CommonModule } from '@angular/common';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { ErrorHandler, ModuleWithProviders, NgModule } from '@angular/core';
import { ErrorHandler, Injector, ModuleWithProviders, NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { ColorPickerModule } from 'ngx-color-picker';
import { TourService as BaseTourService } from 'ngx-ui-tour-core';
import { AutocompleteComponent, AvatarComponent, CachingInterceptor, CanDeactivateGuard, CheckboxGroupComponent, ClipboardService, CodeComponent, CodeEditorComponent, ColorPickerComponent, CompensateScrollbarDirective, ConfirmClickDirective, ControlErrorsComponent, ControlErrorsMessagesComponent, CopyDirective, DarkenPipe, DatePipe, DateTimeEditorComponent, DayOfWeekPipe, DayPipe, DialogRendererComponent, DialogService, DisplayNamePipe, DropdownComponent, DropdownMenuComponent, DurationPipe, EditableTitleComponent, ExternalLinkDirective, FileDropDirective, FileSizePipe, FocusOnInitDirective, FormAlertComponent, FormErrorComponent, FormHintComponent, FromNowPipe, FullDateTimePipe, GlobalErrorHandler, HighlightPipe, HoverBackgroundDirective, IfOnceDirective, ImageSourceDirective, ImageUrlDirective, IndeterminateValueDirective, ISODatePipe, JoinPipe, KeysPipe, KNumberPipe, LanguageSelectorComponent, LayoutComponent, LayoutContainerDirective, LightenPipe, ListViewComponent, LoaderComponent, LoadingInterceptor, LoadingService, LocalizedInputComponent, LocalStoreService, LongHoverDirective, MarkdownDirective, MarkdownInlinePipe, MarkdownPipe, MessageBus, ModalDialogComponent, ModalDirective, ModalPlacementDirective, MonthPipe, PagerComponent, ParentLinkDirective, ProgressBarComponent, RadioGroupComponent, ResizedDirective, ResizeService, ResourceLoaderService, RootViewComponent, SafeHtmlPipe, SafeResourceUrlPipe, SafeUrlPipe, ScrollActiveDirective, ShortcutComponent, ShortcutDirective, ShortcutService, ShortDatePipe, ShortTimePipe, StarsComponent, StatusIconComponent, StopClickDirective, StopDragDirective, SyncScollingDirective, SyncWidthDirective, TabRouterlinkDirective, TagEditorComponent, TemplateWrapperDirective, TempService, TitleComponent, TitleService, ToggleComponent, ToolbarComponent, TooltipDirective, TourService, TourStepDirective, TourTemplateComponent, TransformInputDirective, TranslatePipe, VideoPlayerComponent } from './declarations';
import { AnalyticsService, AutocompleteComponent, AvatarComponent, CachingInterceptor, CanDeactivateGuard, CheckboxGroupComponent, ClipboardService, CodeComponent, CodeEditorComponent, ColorPickerComponent, CompensateScrollbarDirective, ConfirmClickDirective, ControlErrorsComponent, ControlErrorsMessagesComponent, CopyDirective, DarkenPipe, DatePipe, DateTimeEditorComponent, DayOfWeekPipe, DayPipe, DialogRendererComponent, DialogService, DisplayNamePipe, DropdownComponent, DropdownMenuComponent, DurationPipe, EditableTitleComponent, ExternalLinkDirective, FileDropDirective, FileSizePipe, FocusOnInitDirective, FormAlertComponent, FormErrorComponent, FormHintComponent, FromNowPipe, FullDateTimePipe, GlobalErrorHandler, HighlightPipe, HoverBackgroundDirective, IfOnceDirective, ImageSourceDirective, ImageUrlDirective, IndeterminateValueDirective, ISODatePipe, JoinPipe, KeysPipe, KNumberPipe, LanguageSelectorComponent, LayoutComponent, LayoutContainerDirective, LightenPipe, ListViewComponent, LoaderComponent, LoadingInterceptor, LoadingService, LocalizedInputComponent, LocalStoreService, LongHoverDirective, MarkdownDirective, MarkdownInlinePipe, MarkdownPipe, MessageBus, ModalDialogComponent, ModalDirective, ModalPlacementDirective, MonthPipe, PagerComponent, ParentLinkDirective, ProgressBarComponent, RadioGroupComponent, ResizedDirective, ResizeService, ResourceLoaderService, RootViewComponent, SafeHtmlPipe, SafeResourceUrlPipe, SafeUrlPipe, ScrollActiveDirective, ShortcutComponent, ShortcutDirective, ShortcutService, ShortDatePipe, ShortTimePipe, StarsComponent, StatusIconComponent, StopClickDirective, StopDragDirective, SyncScollingDirective, SyncWidthDirective, TabRouterlinkDirective, TagEditorComponent, TemplateWrapperDirective, TempService, TitleComponent, TitleService, ToggleComponent, ToolbarComponent, TooltipDirective, TourService, TourStepDirective, TourTemplateComponent, TransformInputDirective, TranslatePipe, VideoPlayerComponent } from './declarations';

@NgModule({
imports: [
Expand Down Expand Up @@ -206,10 +206,15 @@ import { AutocompleteComponent, AvatarComponent, CachingInterceptor, CanDeactiva
],
})
export class SqxFrameworkModule {
constructor(injector: Injector) {
injector.get(AnalyticsService);
}

public static forRoot(): ModuleWithProviders<SqxFrameworkModule> {
return {
ngModule: SqxFrameworkModule,
providers: [
AnalyticsService,
CanDeactivateGuard,
ClipboardService,
DialogService,
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/app/framework/services/analytics.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/

import { Injectable } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { Types } from './../internal';

type TrackEvent = (name: string, properties: any) => void;
type TrackPage = (url: string) => void;

@Injectable()
export class AnalyticsService {
private readonly globalTrackEvent?: TrackEvent;
private readonly globalTrackPage?: TrackPage;

constructor(router: Router) {
this.globalTrackEvent = (window as any)['trackEvent'];
this.globalTrackPage = (window as any)['trackEvent'];

router.events.subscribe(event => {
if (Types.is(event, NavigationEnd)) {
this.globalTrackPage?.(event.urlAfterRedirects);
}
});
}

public trackEvent(name: string, properties: any) {
this.globalTrackEvent?.(name, properties);
}
}
8 changes: 6 additions & 2 deletions frontend/src/app/framework/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,13 @@ class Connector {

state.changes
.subscribe(change => {
this.state[slice] = change.snapshot;
const eventName = `${slice} - ${change.event}`;

this.devTools?.send(`${slice} - ${change.event}`, this.state);
if (this.devTools) {
this.state[slice] = change.snapshot;

this.devTools?.send(eventName, this.state);
}
});
}
}
Expand Down

0 comments on commit 9e772cc

Please sign in to comment.