@streamscloud/streams-analytics-collector 1.0.5 → 1.0.6

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,7 @@ import type { Client } from '@urql/core';
5
5
  */
6
6
  export declare class AppEventsTracker {
7
7
  private static reported;
8
+ private static playedPercentsByPost;
8
9
  private static gqlEndpoint;
9
10
  private static client;
10
11
  private static organizationId;
@@ -90,8 +91,9 @@ export declare class AppEventsTracker {
90
91
  /**
91
92
  * Track when a post is closed
92
93
  * @param postId - The ID of the post
94
+ * @param streamId - The ID of the stream
93
95
  */
94
- static trackClosed(postId: string): void;
96
+ static trackClosed(postId: string, streamId: string): void;
95
97
  /**
96
98
  * Report an app event to the API
97
99
  * @private
@@ -7,6 +7,7 @@ import AnalyticsQuery from '../analytics.graphql.js';
7
7
  */
8
8
  class AppEventsTracker {
9
9
  static reported = [];
10
+ static playedPercentsByPost = new Map();
10
11
  static gqlEndpoint = '';
11
12
  static client;
12
13
  static organizationId;
@@ -56,8 +57,11 @@ class AppEventsTracker {
56
57
  * @param playedPercents - The percentage of the post that has been played
57
58
  */
58
59
  static trackPostPlaying(postId, playedPercents) {
60
+ // Store the latest played percentage for this post
61
+ this.playedPercentsByPost.set(postId, playedPercents);
62
+ // Only report the event if not already reported and past the minimum threshold
59
63
  if (playedPercents > 0.2 && this.reported.indexOf(postId) === -1) {
60
- this.reportAppEvent(postId, AppEventType.PostView);
64
+ this.reported.push(postId);
61
65
  }
62
66
  }
63
67
  /**
@@ -126,8 +130,17 @@ class AppEventsTracker {
126
130
  /**
127
131
  * Track when a post is closed
128
132
  * @param postId - The ID of the post
133
+ * @param streamId - The ID of the stream
129
134
  */
130
- static trackClosed(postId) {
135
+ static trackClosed(postId, streamId) {
136
+ // Get the stored played percentage for this post
137
+ const playedPercents = this.playedPercentsByPost.get(postId);
138
+ // Report the final ShortVideoView event with the final played percentage when video is stopped
139
+ if (playedPercents !== undefined) {
140
+ this.reportAppEvent(postId, AppEventType.ShortVideoView, streamId, playedPercents);
141
+ }
142
+ // Clean up stored data for this post
143
+ this.playedPercentsByPost.delete(postId);
131
144
  const postIndex = this.reported.indexOf(postId);
132
145
  if (postIndex >= 0) {
133
146
  this.reported.splice(postIndex, 1);
@@ -175,13 +188,6 @@ class AppEventsTracker {
175
188
  console.warn('An attempt to save app event without initializing GraphQL client detected');
176
189
  return;
177
190
  }
178
- // const mutation = `
179
- // mutation TrackAppEvent($input: TrackAppEventInput!) {
180
- // trackAppEvent(input: $input) {
181
- // void
182
- // }
183
- // }
184
- // `;
185
191
  await this.client
186
192
  .mutation(AnalyticsQuery, { input })
187
193
  .toPromise();
@@ -191,13 +197,6 @@ class AppEventsTracker {
191
197
  console.warn('An attempt to save app event without initializing GraphQL endpoint detected');
192
198
  return;
193
199
  }
194
- // const query = `
195
- // mutation TrackAppEvent($input: TrackAppEventInput!) {
196
- // trackAppEvent(input: $input) {
197
- // void
198
- // }
199
- // }
200
- // `;
201
200
  await this.queryGql(AnalyticsQuery, { input });
202
201
  }
203
202
  }
@@ -1,5 +1,6 @@
1
1
  export declare enum AppEventType {
2
2
  PostView = "POST_VIEW",
3
+ ShortVideoView = "SHORT_VIDEO_VIEW",
3
4
  CommunityMessageView = "COMMUNITY_MESSAGE_VIEW",
4
5
  StreamTileImpression = "STREAM_TILE_IMPRESSION",
5
6
  StreamTileClick = "STREAM_TILE_CLICK",
@@ -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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/streams-analytics-collector",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",