From cdc67f41f45fbd8a6837ff7041c8e167534e2029 Mon Sep 17 00:00:00 2001 From: Mikhail Preyskurantov <5574159+mpreyskurantov@users.noreply.github.com> Date: Tue, 6 Aug 2024 19:38:18 +0300 Subject: [PATCH 01/10] ga to matomo (export events) --- src/app/analytics-events.service.ts | 29 +++++++++++ src/app/google-analytics-events.service.ts | 20 ------- .../bootstrap-uploader.component.ts | 6 --- .../export-popup/export-popup.component.ts | 52 ++++++++++++++----- .../import-popup/import-popup.component.ts | 4 -- 5 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 src/app/analytics-events.service.ts delete mode 100644 src/app/google-analytics-events.service.ts diff --git a/src/app/analytics-events.service.ts b/src/app/analytics-events.service.ts new file mode 100644 index 00000000..3754ad62 --- /dev/null +++ b/src/app/analytics-events.service.ts @@ -0,0 +1,29 @@ +import { Injectable } from '@angular/core'; +import { environment } from '../environments/environment'; + +@Injectable({ + providedIn: 'root' +}) + +export class analyticsEventsService { + trackEvent( + /* + eventCategory: string, + eventAction: string, + eventName: string = null, + eventValue: string = null, + */ + ...items + ): void { + + //if(!environment.production) return; + + const _paq = (window as any)._paq || []; + + if(_paq.push) { + const eventArgs = ['trackEvent', ...items]; + //_paq.push(eventArgs); + console.log(eventArgs); + } + } +} diff --git a/src/app/google-analytics-events.service.ts b/src/app/google-analytics-events.service.ts deleted file mode 100644 index 354cc04d..00000000 --- a/src/app/google-analytics-events.service.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Injectable } from '@angular/core'; -import { environment } from '../environments/environment'; - -@Injectable({ - providedIn: 'root' -}) -export class GoogleAnalyticsEventsService { - emitEvent( - eventAction: string, - eventLabel: string): void { - if(!environment.production) return; - - const ga = (window as any).ga; - - if(ga && ga.getAll) { - const _tracker = ga.getAll()[0]; - if(_tracker) _tracker.send('event', 'ThemeBuilder', eventAction, eventLabel); - } - } -} diff --git a/src/app/layouts/bootstrap-uploader/bootstrap-uploader.component.ts b/src/app/layouts/bootstrap-uploader/bootstrap-uploader.component.ts index 986f6681..9cd88b06 100644 --- a/src/app/layouts/bootstrap-uploader/bootstrap-uploader.component.ts +++ b/src/app/layouts/bootstrap-uploader/bootstrap-uploader.component.ts @@ -2,7 +2,6 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; import { alert } from 'devextreme/ui/dialog'; import { NotificationsService } from 'src/app/notification.service'; import { mutePromise } from 'src/app/promise-helper'; -import { GoogleAnalyticsEventsService } from '../../google-analytics-events.service'; import { ImportService } from '../../import.service'; @Component({ @@ -21,7 +20,6 @@ export class BootstrapUploaderComponent { constructor( private importService: ImportService, - private googleAnalyticsEventsService: GoogleAnalyticsEventsService, private notifications: NotificationsService ) {} @@ -60,10 +58,6 @@ export class BootstrapUploaderComponent { }); } - this.googleAnalyticsEventsService.emitEvent( - 'import', - this.version ? 'bootstrap variables (file)' : 'metadata (file)'); - this.imported.emit(); e.component.reset(); }; diff --git a/src/app/layouts/header/export-popup/export-popup.component.ts b/src/app/layouts/header/export-popup/export-popup.component.ts index 137093a5..3fb4b2e2 100644 --- a/src/app/layouts/header/export-popup/export-popup.component.ts +++ b/src/app/layouts/header/export-popup/export-popup.component.ts @@ -4,7 +4,7 @@ import validationEngine from 'devextreme/ui/validation_engine'; import { saveAs } from 'file-saver'; import * as JSZip from 'jszip'; import * as JSZipUtils from 'jszip-utils'; -import { GoogleAnalyticsEventsService } from '../../../google-analytics-events.service'; +import { analyticsEventsService } from '../../../analytics-events.service'; import { ImportService } from '../../../import.service'; import { PopupComponent } from '../popup/popup.component'; import { DxTreeViewComponent, DxScrollViewComponent } from 'devextreme-angular'; @@ -71,8 +71,8 @@ export class ExportPopupComponent implements OnInit { constructor( private importService: ImportService, - private googleAnalyticsEventsService: GoogleAnalyticsEventsService - ) {} + private analyticsEventsService: analyticsEventsService + ) { } changeStep(index: number): void { const START_PAGE_INDEX = 0; @@ -203,9 +203,13 @@ export class ExportPopupComponent implements OnInit { } exportCss(save: boolean): Promise { - this.googleAnalyticsEventsService.emitEvent( - 'export', - 'save css (' + this.importService.getThemeName() + ')'); + if (save) { + this.analyticsEventsService.trackEvent( + 'TB: Export', + 'Tb download css', + this.importService.getThemeName() + ); + } this.contentReady = false; return this.importService.exportCss(this.schemeName, this.makeSwatch, this.getSelectedWidgets(), this.removeExternalResources) @@ -221,9 +225,13 @@ export class ExportPopupComponent implements OnInit { } exportMeta(save: boolean): void { - this.googleAnalyticsEventsService.emitEvent( - 'export', - 'save metadata (' + this.importService.getThemeName() + ')'); + if(save) { + this.analyticsEventsService.trackEvent( + 'TB: Export', + 'Tb download metadata', + this.importService.getThemeName() + ); + } // eslint-disable-next-line @typescript-eslint/no-floating-promises this.importService.exportMetadata(this.schemeName, this.makeSwatch, this.getSelectedWidgets(), this.removeExternalResources).then((metaString) => { @@ -233,6 +241,12 @@ export class ExportPopupComponent implements OnInit { } exportZip(): void { + this.analyticsEventsService.trackEvent( + 'TB: Export', + 'Tb download zip', + this.importService.getThemeName() + ); + const zip = new JSZip(); const fontExtension = ['ttf', 'woff', 'woff2']; const theme = { @@ -264,10 +278,20 @@ export class ExportPopupComponent implements OnInit { } copy(): void { - if(this.needMeta) { + if (this.needMeta) { + this.analyticsEventsService.trackEvent( + 'TB: Export', + 'Tb copy metadata', + this.importService.getThemeName() + ); this.exportMeta(false); this.copyAreaActive = true; } else { + this.analyticsEventsService.trackEvent( + 'TB: Export', + 'Tb copy css', + this.importService.getThemeName() + ); this.exportCss(false) .then(() => this.copyAreaActive = true) .catch((e) => { @@ -277,9 +301,11 @@ export class ExportPopupComponent implements OnInit { } copyFileContent(): void { - this.googleAnalyticsEventsService.emitEvent( - 'export', - 'copy ' + (this.needMeta ? 'metadata' : 'css') + ' (' + this.importService.getThemeName() + ')'); + this.analyticsEventsService.trackEvent( + 'TB: Export', + 'Tb copy ' + (this.needMeta ? 'metadata' : 'css'), + this.importService.getThemeName() + ); } ngOnInit(): void { diff --git a/src/app/layouts/header/import-popup/import-popup.component.ts b/src/app/layouts/header/import-popup/import-popup.component.ts index 32f08e2e..870708d0 100644 --- a/src/app/layouts/header/import-popup/import-popup.component.ts +++ b/src/app/layouts/header/import-popup/import-popup.component.ts @@ -1,5 +1,4 @@ import { Component, ViewChild } from '@angular/core'; -import { GoogleAnalyticsEventsService } from '../../../google-analytics-events.service'; import { ImportService } from '../../../import.service'; import { PopupComponent } from '../popup/popup.component'; @@ -13,7 +12,6 @@ export class ImportPopupComponent { constructor( private importService: ImportService, - private googleAnalyticsEventsService: GoogleAnalyticsEventsService ) { } radioGroupData = [{ @@ -40,8 +38,6 @@ export class ImportPopupComponent { importValue = ''; applyClick(t): void { - this.googleAnalyticsEventsService.emitEvent('import', 'metadata'); - this.importService.importMetadata(t.value, 'advanced').then(() => { this.popup.hide(); t.value = ''; From ab80846c9352f95eee6a76a4610110c537295d73 Mon Sep 17 00:00:00 2001 From: Mikhail Preyskurantov <5574159+mpreyskurantov@users.noreply.github.com> Date: Tue, 6 Aug 2024 19:40:17 +0300 Subject: [PATCH 02/10] move init script to end --- src/index.html | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/index.html b/src/index.html index 5b816390..5dd4e8db 100644 --- a/src/index.html +++ b/src/index.html @@ -46,15 +46,6 @@ changeMetaContent(); - - - -