Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track custom analytics events #242

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Capacitor } from '@capacitor/core';
import { ConfigurationService } from '@picsa/configuration/src';
import { APP_VERSION } from '@picsa/environments/src';
import { PicsaAsyncService } from '@picsa/shared/services/asyncService.service';
import { AnalyticsService } from '@picsa/shared/services/core/analytics.service';
import { PicsaDatabase_V2_Service, PicsaDatabaseAttachmentService } from '@picsa/shared/services/core/db_v2';
import { FileService } from '@picsa/shared/services/core/file.service';
import { NativeStorageService } from '@picsa/shared/services/native';
Expand All @@ -21,7 +22,8 @@ export class ResourcesToolService extends PicsaAsyncService {
private dbAttachmentService: PicsaDatabaseAttachmentService,
private configurationService: ConfigurationService,
private nativeStorageService: NativeStorageService,
private fileService: FileService
private fileService: FileService,
private analyticsService: AnalyticsService
) {
super();
}
Expand Down Expand Up @@ -71,6 +73,8 @@ export class ResourcesToolService extends PicsaAsyncService {
}

public async openFileResource(uri: string, mimetype: string) {
// track the resource open event
this.analyticsService.trackResourceOpen();
if (Capacitor.isNativePlatform()) {
try {
this.nativeStorageService.openFileURI(uri, mimetype);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, ElementRef, HostBinding, Input, OnDestroy } from '@angular/core';
import { Capacitor } from '@capacitor/core';
import { ScreenOrientation } from '@capacitor/screen-orientation';
import { AnalyticsService } from '@picsa/shared/services/core/analytics.service';
import { CapacitorVideoPlayer, CapacitorVideoPlayerPlugin, capVideoPlayerOptions } from 'capacitor-video-player';

// Fix listeners missing from type
Expand Down Expand Up @@ -53,7 +54,7 @@ export class VideoPlayerComponent implements OnDestroy {

private pauseTime: number = 0;

constructor(private elementRef: ElementRef<HTMLDivElement>) {}
constructor(private elementRef: ElementRef<HTMLDivElement>, private analyticsService: AnalyticsService) {}

async ngOnDestroy() {
await this.videoPlayer.stopAllPlayers();
Expand All @@ -74,6 +75,8 @@ export class VideoPlayerComponent implements OnDestroy {
if (Capacitor.isNativePlatform()) {
this.initialised = false;
}
// track video play event
this.analyticsService.trackVideoPlay(this.playerId);
// Initialise player any time playback triggered in case url updated (e.g. downloaded after init)
await this.initPlayer();
this.videoPlayer.play({ playerId: this.playerId }).then(() => {
Expand Down
20 changes: 18 additions & 2 deletions libs/shared/src/services/core/analytics.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { NavigationEnd,Router } from '@angular/router';
import { NavigationEnd, Router } from '@angular/router';
import { Capacitor } from '@capacitor/core';
import { FirebaseAnalytics } from '@capacitor-community/firebase-analytics';
import { APP_VERSION,ENVIRONMENT } from '@picsa/environments';
import { APP_VERSION, ENVIRONMENT } from '@picsa/environments';

@Injectable({ providedIn: 'root' })
/**
Expand Down Expand Up @@ -35,4 +35,20 @@ export class AnalyticsService {
}
});
}

// Method to track when users play a video
public trackVideoPlay(videoId: string) {
this.firebaseAnalytics.logEvent({
name: 'video_play',
params: { video_id: videoId, app_version: APP_VERSION },
});
}

// Method to track when users opens resource file
public trackResourceOpen() {
this.firebaseAnalytics.logEvent({
name: 'open_resource_file',
params: { app_version: APP_VERSION },
});
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"dexie": "^3.2.3",
"downloadjs": "^1.4.7",
"enketo-core": "^6.1.3",
"fast-xml-parser": "^4.2.2",
"fast-xml-parser": "4.2.2",
"firebase": "^9.16.0",
"form-data": "^4.0.0",
"fuse.js": "^7.0.0",
Expand Down
Loading
Loading