From 62cf7426761773ab4895e1404d11fb86c21bd5cb Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 1 Feb 2022 12:44:37 +0100 Subject: [PATCH] feat: method to trigger stop manually in the connector --- Readme.md | 6 ++++++ src/PlayerAnalyticsConnector.ts | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/Readme.md b/Readme.md index 4437bf7..9bf3257 100644 --- a/Readme.md +++ b/Readme.md @@ -62,6 +62,12 @@ playerAnalytics.reportWarning({ }); ``` +```js +// when leaving the player, to stop the analytics in a correct manor +playerAnalytics.reportStop(); +playerAnalytics.destroy(); +``` + ### Manual Event Triggering ```js diff --git a/src/PlayerAnalyticsConnector.ts b/src/PlayerAnalyticsConnector.ts index f381699..9b7a554 100644 --- a/src/PlayerAnalyticsConnector.ts +++ b/src/PlayerAnalyticsConnector.ts @@ -154,6 +154,15 @@ export class PlayerAnalyticsConnector { }); } + public reportStop() { + this.playerAnalytics.stopped({ + event: EPASEvents.ended, + ...this.playbackState(), + payload: { reason: "aborted" }, + }); + this.stopInterval(); + } + public reportError(error: TErrorEventPayload) { this.playerAnalytics.error({ event: EPASEvents.error,