Skip to content

Commit

Permalink
included a method to in analytics.service for video play tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
OchiengPaul442 committed Feb 24, 2024
1 parent 4a7ace9 commit cb037eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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
12 changes: 10 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,12 @@ 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 },
});
}
}

0 comments on commit cb037eb

Please sign in to comment.