@streamscloud/streams-analytics-collector 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ import type { Client } from '@urql/core';
6
6
  export declare class AppEventsTracker {
7
7
  private static reported;
8
8
  private static playedPercentsByPost;
9
+ private static videosByPage;
9
10
  private static gqlEndpoint;
10
11
  private static client;
11
12
  private static organizationId;
@@ -31,6 +32,20 @@ export declare class AppEventsTracker {
31
32
  * @param profileId - The profile ID
32
33
  */
33
34
  static setProfileId(profileId: string): void;
35
+ /**
36
+ * Track the progress of a short video within a page
37
+ * @param pageId - The ID of the page containing the video
38
+ * @param videoId - The ID of the video
39
+ * @param playedPercents - The percentage of the video that has been played
40
+ * @param streamId - The ID of the stream containing the video (optional)
41
+ */
42
+ static trackShortVideoProgress(pageId: string, videoId: string, playedPercents: number, streamId?: string): void;
43
+ /**
44
+ * Report all video views for a page when it's deactivated
45
+ * @param pageId - The ID of the page that's being deactivated
46
+ * @param streamId - The ID of the stream containing the page (optional)
47
+ */
48
+ static reportPageVideoViews(pageId: string, streamId?: string): void;
34
49
  /**
35
50
  * Track when a post is opened
36
51
  * @param postId - The ID of the post
@@ -41,8 +56,9 @@ export declare class AppEventsTracker {
41
56
  * Track when a post is being played
42
57
  * @param postId - The ID of the post
43
58
  * @param playedPercents - The percentage of the post that has been played
59
+ * @deprecated Consider using trackShortVideoProgress for better tracking of multiple videos
44
60
  */
45
- static trackPostPlaying(postId: string, playedPercents: number): void;
61
+ static reportVideoPostPlayingProgress(postId: string, playedPercents: number): void;
46
62
  /**
47
63
  * Track when a community message is opened
48
64
  * @param messageId - The ID of the message
@@ -92,6 +108,7 @@ export declare class AppEventsTracker {
92
108
  * Track when a post is closed
93
109
  * @param postId - The ID of the post
94
110
  * @param streamId - The ID of the stream
111
+ * @deprecated Consider using trackShortVideoProgress and reportPageVideoViews for better tracking of multiple videos
95
112
  */
96
113
  static trackClosed(postId: string, streamId: string): void;
97
114
  /**
@@ -8,6 +8,8 @@ import AnalyticsQuery from '../analytics.graphql.js';
8
8
  class AppEventsTracker {
9
9
  static reported = [];
10
10
  static playedPercentsByPost = new Map();
11
+ // Store video data by page ID to handle multiple videos per page
12
+ static videosByPage = new Map();
11
13
  static gqlEndpoint = '';
12
14
  static client;
13
15
  static organizationId;
@@ -43,6 +45,46 @@ class AppEventsTracker {
43
45
  static setProfileId(profileId) {
44
46
  this.profileId = profileId;
45
47
  }
48
+ /**
49
+ * Track the progress of a short video within a page
50
+ * @param pageId - The ID of the page containing the video
51
+ * @param videoId - The ID of the video
52
+ * @param playedPercents - The percentage of the video that has been played
53
+ * @param streamId - The ID of the stream containing the video (optional)
54
+ */
55
+ static trackShortVideoProgress(pageId, videoId, playedPercents, streamId) {
56
+ // Initialize page map if it doesn't exist
57
+ if (!this.videosByPage.has(pageId)) {
58
+ this.videosByPage.set(pageId, new Map());
59
+ }
60
+ // Update the played percentage for this video on this page
61
+ // Only store the maximum percentage in case of looping videos
62
+ const pageVideos = this.videosByPage.get(pageId);
63
+ if (pageVideos) {
64
+ const videoKey = `${videoId}|${streamId || ''}`;
65
+ const currentMaxPercent = pageVideos.get(videoKey) || 0;
66
+ // Store only the maximum played percentage value
67
+ // This ensures we don't decrease progress when video loops
68
+ pageVideos.set(videoKey, Math.max(currentMaxPercent, playedPercents));
69
+ }
70
+ }
71
+ /**
72
+ * Report all video views for a page when it's deactivated
73
+ * @param pageId - The ID of the page that's being deactivated
74
+ * @param streamId - The ID of the stream containing the page (optional)
75
+ */
76
+ static reportPageVideoViews(pageId, streamId) {
77
+ const pageVideos = this.videosByPage.get(pageId);
78
+ if (pageVideos) {
79
+ // Report all video views for this page
80
+ pageVideos.forEach((playedPercents, videoKey) => {
81
+ const [videoId, videoStreamId] = videoKey.split('|');
82
+ this.reportAppEvent(videoId, AppEventType.ShortVideoView, videoStreamId || streamId, playedPercents);
83
+ });
84
+ // Clean up the tracking data for this page
85
+ this.videosByPage.delete(pageId);
86
+ }
87
+ }
46
88
  /**
47
89
  * Track when a post is opened
48
90
  * @param postId - The ID of the post
@@ -55,14 +97,11 @@ class AppEventsTracker {
55
97
  * Track when a post is being played
56
98
  * @param postId - The ID of the post
57
99
  * @param playedPercents - The percentage of the post that has been played
100
+ * @deprecated Consider using trackShortVideoProgress for better tracking of multiple videos
58
101
  */
59
- static trackPostPlaying(postId, playedPercents) {
102
+ static reportVideoPostPlayingProgress(postId, playedPercents) {
60
103
  // Store the latest played percentage for this post
61
104
  this.playedPercentsByPost.set(postId, playedPercents);
62
- // Only report the event if not already reported and past the minimum threshold
63
- if (playedPercents > 0.2 && this.reported.indexOf(postId) === -1) {
64
- this.reported.push(postId);
65
- }
66
105
  }
67
106
  /**
68
107
  * Track when a community message is opened
@@ -131,6 +170,7 @@ class AppEventsTracker {
131
170
  * Track when a post is closed
132
171
  * @param postId - The ID of the post
133
172
  * @param streamId - The ID of the stream
173
+ * @deprecated Consider using trackShortVideoProgress and reportPageVideoViews for better tracking of multiple videos
134
174
  */
135
175
  static trackClosed(postId, streamId) {
136
176
  // Get the stored played percentage for this post
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/streams-analytics-collector",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",