-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: track custom analytics events #243
Changes from 6 commits
9e91977
ee0b944
c40ca9c
aca790b
f9e8301
ab06048
1bc6b5c
8b82c23
a80d87c
eb39201
6cf110b
b55a77f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit(blocking) - I see the tests are failing and they refer to this import in the errors (not sure if you have seen). import { AnalyticsService } from '../../services/core/analytics.service'; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @chrismclarke, I noticed the build errors earlier and was working on resolving them. Your explanation has provided clarity on the issue, and I’m now in a better position to address it. Thanks |
||
import { CapacitorVideoPlayer, CapacitorVideoPlayerPlugin, capVideoPlayerOptions } from 'capacitor-video-player'; | ||
|
||
// Fix listeners missing from type | ||
|
@@ -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(); | ||
|
@@ -74,6 +75,8 @@ export class VideoPlayerComponent implements OnDestroy { | |
if (Capacitor.isNativePlatform()) { | ||
this.initialised = false; | ||
} | ||
// Track video play event | ||
this.analyticsService.trackVideoPlay(this.playerId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit(non-blocking): currently the playerId is a randomly generated id, so it doesn't really hold any analytics value. It might be good to implement player IDs as suggested in #241 (but not the full storage solution) so that we can track the id of the resource when passed to the video player and for logging in analytics This could either be included in this pr (would only be a few lines of code), or as part of a follow-up |
||
// 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(() => { | ||
|
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' }) | ||
/** | ||
|
@@ -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 }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit(non-blocking): |
||
}); | ||
} | ||
|
||
// Method to track when users opens resource file | ||
public trackResourceOpen() { | ||
this.firebaseAnalytics.logEvent({ | ||
name: 'open_resource_file', | ||
params: { app_version: APP_VERSION }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit(non-blocking): same as above, although would also be nice to have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will work on that. |
||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit(blocking): Nice we can track the resource open event but would be even better if we could track the id of the resource being opened. So in order to achieve this we either need to pass an extra argument to the
openFileResource
method (e.g.id
), or call the tracking function within theresource-item-file
component itself which does have the id.I think technically the better solution would probably be passing the id to the service, as that keeps the component more focused on the UI and service on side-effects