@streamscloud/streams-analytics-collector 1.0.5 → 1.0.7
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.
|
@@ -5,6 +5,8 @@ import type { Client } from '@urql/core';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class AppEventsTracker {
|
|
7
7
|
private static reported;
|
|
8
|
+
private static playedPercentsByPost;
|
|
9
|
+
private static videosByPage;
|
|
8
10
|
private static gqlEndpoint;
|
|
9
11
|
private static client;
|
|
10
12
|
private static organizationId;
|
|
@@ -30,6 +32,20 @@ export declare class AppEventsTracker {
|
|
|
30
32
|
* @param profileId - The profile ID
|
|
31
33
|
*/
|
|
32
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;
|
|
33
49
|
/**
|
|
34
50
|
* Track when a post is opened
|
|
35
51
|
* @param postId - The ID of the post
|
|
@@ -40,8 +56,9 @@ export declare class AppEventsTracker {
|
|
|
40
56
|
* Track when a post is being played
|
|
41
57
|
* @param postId - The ID of the post
|
|
42
58
|
* @param playedPercents - The percentage of the post that has been played
|
|
59
|
+
* @deprecated Consider using trackShortVideoProgress for better tracking of multiple videos
|
|
43
60
|
*/
|
|
44
|
-
static
|
|
61
|
+
static reportVideoPostPlayingProgress(postId: string, playedPercents: number): void;
|
|
45
62
|
/**
|
|
46
63
|
* Track when a community message is opened
|
|
47
64
|
* @param messageId - The ID of the message
|
|
@@ -90,8 +107,10 @@ export declare class AppEventsTracker {
|
|
|
90
107
|
/**
|
|
91
108
|
* Track when a post is closed
|
|
92
109
|
* @param postId - The ID of the post
|
|
110
|
+
* @param streamId - The ID of the stream
|
|
111
|
+
* @deprecated Consider using trackShortVideoProgress and reportPageVideoViews for better tracking of multiple videos
|
|
93
112
|
*/
|
|
94
|
-
static trackClosed(postId: string): void;
|
|
113
|
+
static trackClosed(postId: string, streamId: string): void;
|
|
95
114
|
/**
|
|
96
115
|
* Report an app event to the API
|
|
97
116
|
* @private
|
|
@@ -7,6 +7,9 @@ import AnalyticsQuery from '../analytics.graphql.js';
|
|
|
7
7
|
*/
|
|
8
8
|
class AppEventsTracker {
|
|
9
9
|
static reported = [];
|
|
10
|
+
static playedPercentsByPost = new Map();
|
|
11
|
+
// Store video data by page ID to handle multiple videos per page
|
|
12
|
+
static videosByPage = new Map();
|
|
10
13
|
static gqlEndpoint = '';
|
|
11
14
|
static client;
|
|
12
15
|
static organizationId;
|
|
@@ -42,6 +45,41 @@ class AppEventsTracker {
|
|
|
42
45
|
static setProfileId(profileId) {
|
|
43
46
|
this.profileId = profileId;
|
|
44
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
|
+
const pageVideos = this.videosByPage.get(pageId);
|
|
62
|
+
if (pageVideos) {
|
|
63
|
+
pageVideos.set(`${videoId}|${streamId || ''}`, playedPercents);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Report all video views for a page when it's deactivated
|
|
68
|
+
* @param pageId - The ID of the page that's being deactivated
|
|
69
|
+
* @param streamId - The ID of the stream containing the page (optional)
|
|
70
|
+
*/
|
|
71
|
+
static reportPageVideoViews(pageId, streamId) {
|
|
72
|
+
const pageVideos = this.videosByPage.get(pageId);
|
|
73
|
+
if (pageVideos) {
|
|
74
|
+
// Report all video views for this page
|
|
75
|
+
pageVideos.forEach((playedPercents, videoKey) => {
|
|
76
|
+
const [videoId, videoStreamId] = videoKey.split('|');
|
|
77
|
+
this.reportAppEvent(videoId, AppEventType.ShortVideoView, videoStreamId || streamId, playedPercents);
|
|
78
|
+
});
|
|
79
|
+
// Clean up the tracking data for this page
|
|
80
|
+
this.videosByPage.delete(pageId);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
45
83
|
/**
|
|
46
84
|
* Track when a post is opened
|
|
47
85
|
* @param postId - The ID of the post
|
|
@@ -54,11 +92,11 @@ class AppEventsTracker {
|
|
|
54
92
|
* Track when a post is being played
|
|
55
93
|
* @param postId - The ID of the post
|
|
56
94
|
* @param playedPercents - The percentage of the post that has been played
|
|
95
|
+
* @deprecated Consider using trackShortVideoProgress for better tracking of multiple videos
|
|
57
96
|
*/
|
|
58
|
-
static
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
97
|
+
static reportVideoPostPlayingProgress(postId, playedPercents) {
|
|
98
|
+
// Store the latest played percentage for this post
|
|
99
|
+
this.playedPercentsByPost.set(postId, playedPercents);
|
|
62
100
|
}
|
|
63
101
|
/**
|
|
64
102
|
* Track when a community message is opened
|
|
@@ -126,8 +164,18 @@ class AppEventsTracker {
|
|
|
126
164
|
/**
|
|
127
165
|
* Track when a post is closed
|
|
128
166
|
* @param postId - The ID of the post
|
|
167
|
+
* @param streamId - The ID of the stream
|
|
168
|
+
* @deprecated Consider using trackShortVideoProgress and reportPageVideoViews for better tracking of multiple videos
|
|
129
169
|
*/
|
|
130
|
-
static trackClosed(postId) {
|
|
170
|
+
static trackClosed(postId, streamId) {
|
|
171
|
+
// Get the stored played percentage for this post
|
|
172
|
+
const playedPercents = this.playedPercentsByPost.get(postId);
|
|
173
|
+
// Report the final ShortVideoView event with the final played percentage when video is stopped
|
|
174
|
+
if (playedPercents !== undefined) {
|
|
175
|
+
this.reportAppEvent(postId, AppEventType.ShortVideoView, streamId, playedPercents);
|
|
176
|
+
}
|
|
177
|
+
// Clean up stored data for this post
|
|
178
|
+
this.playedPercentsByPost.delete(postId);
|
|
131
179
|
const postIndex = this.reported.indexOf(postId);
|
|
132
180
|
if (postIndex >= 0) {
|
|
133
181
|
this.reported.splice(postIndex, 1);
|
|
@@ -175,13 +223,6 @@ class AppEventsTracker {
|
|
|
175
223
|
console.warn('An attempt to save app event without initializing GraphQL client detected');
|
|
176
224
|
return;
|
|
177
225
|
}
|
|
178
|
-
// const mutation = `
|
|
179
|
-
// mutation TrackAppEvent($input: TrackAppEventInput!) {
|
|
180
|
-
// trackAppEvent(input: $input) {
|
|
181
|
-
// void
|
|
182
|
-
// }
|
|
183
|
-
// }
|
|
184
|
-
// `;
|
|
185
226
|
await this.client
|
|
186
227
|
.mutation(AnalyticsQuery, { input })
|
|
187
228
|
.toPromise();
|
|
@@ -191,13 +232,6 @@ class AppEventsTracker {
|
|
|
191
232
|
console.warn('An attempt to save app event without initializing GraphQL endpoint detected');
|
|
192
233
|
return;
|
|
193
234
|
}
|
|
194
|
-
// const query = `
|
|
195
|
-
// mutation TrackAppEvent($input: TrackAppEventInput!) {
|
|
196
|
-
// trackAppEvent(input: $input) {
|
|
197
|
-
// void
|
|
198
|
-
// }
|
|
199
|
-
// }
|
|
200
|
-
// `;
|
|
201
235
|
await this.queryGql(AnalyticsQuery, { input });
|
|
202
236
|
}
|
|
203
237
|
}
|
package/dist/analytics/types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
var AppEventType;
|
|
2
2
|
(function (AppEventType) {
|
|
3
3
|
AppEventType["PostView"] = "POST_VIEW";
|
|
4
|
+
AppEventType["ShortVideoView"] = "SHORT_VIDEO_VIEW";
|
|
4
5
|
AppEventType["CommunityMessageView"] = "COMMUNITY_MESSAGE_VIEW";
|
|
5
6
|
AppEventType["StreamTileImpression"] = "STREAM_TILE_IMPRESSION";
|
|
6
7
|
AppEventType["StreamTileClick"] = "STREAM_TILE_CLICK";
|