@streamscloud/streams-analytics-collector 2.0.4 → 2.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.
@@ -17,7 +17,6 @@ export declare class AppEventsTracker {
17
17
  * @param client - The URQL client instance
18
18
  */
19
19
  static setClient(client: Client): void;
20
- static setClientNew(client: Client): void;
21
20
  /**
22
21
  * Set the GraphQL endpoint for making API calls (for non-authorized calls)
23
22
  * @param endpoint - The GraphQL endpoint URL
@@ -140,6 +139,45 @@ export declare class AppEventsTracker {
140
139
  * @param adId - The unique ad ID for this element
141
140
  */
142
141
  static trackAdImpressionWithVisibility(el: HTMLElement, adId: string): void;
142
+ /**
143
+ * Track when a short video is shown to the user (basic, immediate call)
144
+ * @param videoId - The ID of the short video
145
+ */
146
+ static trackShortVideoImpression(videoId: string): void;
147
+ /**
148
+ * Track when a short video is shown to the user, using viewport visibility tracking.
149
+ * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
150
+ * The event is only fired once per videoId per session/visit.
151
+ *
152
+ * @param el - The DOM element to observe (e.g., the video element)
153
+ * @param videoId - The unique video ID for this element
154
+ */
155
+ static trackShortVideoImpressionWithVisibility(el: HTMLElement, videoId: string): void;
156
+ /**
157
+ * Track when a short video is viewed by the user
158
+ * @param videoId - The ID of the short video
159
+ * @param playedPercents - The percentage of the video that was played (optional)
160
+ */
161
+ static trackShortVideoView(videoId: string): void;
162
+ /**
163
+ * Track when a product in a short video is clicked
164
+ * @param productId - The ID of the product
165
+ */
166
+ static trackShortVideoProductClick(productId: string): void;
167
+ /**
168
+ * Track when a product in a short video is shown to the user (basic, immediate call)
169
+ * @param productId - The ID of the product
170
+ */
171
+ static trackShortVideoProductImpression(productId: string): void;
172
+ /**
173
+ * Track when a product in a short video is shown to the user, using viewport visibility tracking.
174
+ * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
175
+ * The event is only fired once per productId per session/visit.
176
+ *
177
+ * @param el - The DOM element to observe (e.g., the product element)
178
+ * @param productId - The unique product ID for this element
179
+ */
180
+ static trackShortVideoProductImpressionWithVisibility(el: HTMLElement, productId: string): void;
143
181
  /**
144
182
  * Report an app event to the API
145
183
  * @private
@@ -1,5 +1,6 @@
1
1
  import { AppEventType, CommunityMessageStatus } from './types.js';
2
- import TrackAppEvent from '../analytics.graphql.js';
2
+ import InternalTrackAppEvent from '../internal-analytics.graphql.js';
3
+ import TrackAppEvent from '../external-analytics.graphql.js';
3
4
  import { ViewportVisibilityTracker } from './ViewportVisibilityTracker.js';
4
5
 
5
6
  /**
@@ -24,10 +25,6 @@ class AppEventsTracker {
24
25
  this.client = client;
25
26
  this.useClient = true;
26
27
  }
27
- static setClientNew(client) {
28
- this.client = client;
29
- this.useClient = true;
30
- }
31
28
  /**
32
29
  * Set the GraphQL endpoint for making API calls (for non-authorized calls)
33
30
  * @param endpoint - The GraphQL endpoint URL
@@ -237,6 +234,67 @@ class AppEventsTracker {
237
234
  });
238
235
  // The ViewportVisibilityTracker will call the callback when visible
239
236
  }
237
+ /**
238
+ * Track when a short video is shown to the user (basic, immediate call)
239
+ * @param videoId - The ID of the short video
240
+ */
241
+ static trackShortVideoImpression(videoId) {
242
+ this.reportAppEvent(videoId, AppEventType.ShortVideoImpression);
243
+ }
244
+ /**
245
+ * Track when a short video is shown to the user, using viewport visibility tracking.
246
+ * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
247
+ * The event is only fired once per videoId per session/visit.
248
+ *
249
+ * @param el - The DOM element to observe (e.g., the video element)
250
+ * @param videoId - The unique video ID for this element
251
+ */
252
+ static trackShortVideoImpressionWithVisibility(el, videoId) {
253
+ if (!el || !videoId)
254
+ return;
255
+ ViewportVisibilityTracker.registerTile(el, videoId, (vid) => {
256
+ this.reportAppEvent(vid, AppEventType.ShortVideoImpression);
257
+ });
258
+ // The ViewportVisibilityTracker will call the callback when visible
259
+ }
260
+ /**
261
+ * Track when a short video is viewed by the user
262
+ * @param videoId - The ID of the short video
263
+ * @param playedPercents - The percentage of the video that was played (optional)
264
+ */
265
+ static trackShortVideoView(videoId) {
266
+ this.reportAppEvent(videoId, AppEventType.ShortVideoView);
267
+ }
268
+ /**
269
+ * Track when a product in a short video is clicked
270
+ * @param productId - The ID of the product
271
+ */
272
+ static trackShortVideoProductClick(productId) {
273
+ this.reportAppEvent(productId, AppEventType.ShortVideoProductClick);
274
+ }
275
+ /**
276
+ * Track when a product in a short video is shown to the user (basic, immediate call)
277
+ * @param productId - The ID of the product
278
+ */
279
+ static trackShortVideoProductImpression(productId) {
280
+ this.reportAppEvent(productId, AppEventType.ShortVideoProductImpression);
281
+ }
282
+ /**
283
+ * Track when a product in a short video is shown to the user, using viewport visibility tracking.
284
+ * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
285
+ * The event is only fired once per productId per session/visit.
286
+ *
287
+ * @param el - The DOM element to observe (e.g., the product element)
288
+ * @param productId - The unique product ID for this element
289
+ */
290
+ static trackShortVideoProductImpressionWithVisibility(el, productId) {
291
+ if (!el || !productId)
292
+ return;
293
+ ViewportVisibilityTracker.registerTile(el, productId, (pid) => {
294
+ this.reportAppEvent(pid, AppEventType.ShortVideoProductImpression);
295
+ });
296
+ // The ViewportVisibilityTracker will call the callback when visible
297
+ }
240
298
  /**
241
299
  * Report an app event to the API
242
300
  * @private
@@ -280,7 +338,7 @@ class AppEventsTracker {
280
338
  console.warn("An attempt to save app event without initializing GraphQL client detected");
281
339
  return;
282
340
  }
283
- await this.client.mutation(TrackAppEvent, { input }).toPromise();
341
+ await this.client.mutation(InternalTrackAppEvent, { input }).toPromise();
284
342
  }
285
343
  else {
286
344
  if (!this.gqlEndpoint) {
@@ -1,16 +1,21 @@
1
1
  export declare enum AppEventType {
2
+ AdClick = "AD_CLICK",
3
+ AdImpression = "AD_IMPRESSION",
4
+ CommunityMessageView = "COMMUNITY_MESSAGE_VIEW",
5
+ ContributionCreated = "CONTRIBUTION_CREATED",
2
6
  PostView = "POST_VIEW",
7
+ ShortVideoImpression = "SHORT_VIDEO_IMPRESSION",
8
+ ShortVideoProductClick = "SHORT_VIDEO_PRODUCT_CLICK",
9
+ ShortVideoProductImpression = "SHORT_VIDEO_PRODUCT_IMPRESSION",
3
10
  ShortVideoView = "SHORT_VIDEO_VIEW",
4
- CommunityMessageView = "COMMUNITY_MESSAGE_VIEW",
5
- StreamTileImpression = "STREAM_TILE_IMPRESSION",
6
- StreamTileClick = "STREAM_TILE_CLICK",
7
- StreamView = "STREAM_VIEW",
8
11
  StreamEngagementTime = "STREAM_ENGAGEMENT_TIME",
9
- StreamScrollDepth = "STREAM_SCROLL_DEPTH",
10
12
  StreamPageView = "STREAM_PAGE_VIEW",
11
13
  StreamProductClick = "STREAM_PRODUCT_CLICK",
12
- AdImpression = "AD_IMPRESSION",
13
- AdClick = "AD_CLICK"
14
+ StreamProductImpression = "STREAM_PRODUCT_IMPRESSION",
15
+ StreamScrollDepth = "STREAM_SCROLL_DEPTH",
16
+ StreamTileClick = "STREAM_TILE_CLICK",
17
+ StreamTileImpression = "STREAM_TILE_IMPRESSION",
18
+ StreamView = "STREAM_VIEW"
14
19
  }
15
20
  export declare enum CommunityMessageStatus {
16
21
  Sent = "SENT",
@@ -1,17 +1,22 @@
1
1
  var AppEventType;
2
2
  (function (AppEventType) {
3
+ AppEventType["AdClick"] = "AD_CLICK";
4
+ AppEventType["AdImpression"] = "AD_IMPRESSION";
5
+ AppEventType["CommunityMessageView"] = "COMMUNITY_MESSAGE_VIEW";
6
+ AppEventType["ContributionCreated"] = "CONTRIBUTION_CREATED";
3
7
  AppEventType["PostView"] = "POST_VIEW";
8
+ AppEventType["ShortVideoImpression"] = "SHORT_VIDEO_IMPRESSION";
9
+ AppEventType["ShortVideoProductClick"] = "SHORT_VIDEO_PRODUCT_CLICK";
10
+ AppEventType["ShortVideoProductImpression"] = "SHORT_VIDEO_PRODUCT_IMPRESSION";
4
11
  AppEventType["ShortVideoView"] = "SHORT_VIDEO_VIEW";
5
- AppEventType["CommunityMessageView"] = "COMMUNITY_MESSAGE_VIEW";
6
- AppEventType["StreamTileImpression"] = "STREAM_TILE_IMPRESSION";
7
- AppEventType["StreamTileClick"] = "STREAM_TILE_CLICK";
8
- AppEventType["StreamView"] = "STREAM_VIEW";
9
12
  AppEventType["StreamEngagementTime"] = "STREAM_ENGAGEMENT_TIME";
10
- AppEventType["StreamScrollDepth"] = "STREAM_SCROLL_DEPTH";
11
13
  AppEventType["StreamPageView"] = "STREAM_PAGE_VIEW";
12
14
  AppEventType["StreamProductClick"] = "STREAM_PRODUCT_CLICK";
13
- AppEventType["AdImpression"] = "AD_IMPRESSION";
14
- AppEventType["AdClick"] = "AD_CLICK";
15
+ AppEventType["StreamProductImpression"] = "STREAM_PRODUCT_IMPRESSION";
16
+ AppEventType["StreamScrollDepth"] = "STREAM_SCROLL_DEPTH";
17
+ AppEventType["StreamTileClick"] = "STREAM_TILE_CLICK";
18
+ AppEventType["StreamTileImpression"] = "STREAM_TILE_IMPRESSION";
19
+ AppEventType["StreamView"] = "STREAM_VIEW";
15
20
  })(AppEventType || (AppEventType = {}));
16
21
  var CommunityMessageStatus;
17
22
  (function (CommunityMessageStatus) {
@@ -0,0 +1,3 @@
1
+ var TrackAppEvent = "mutation TrackAppEvent($input: ExternalTrackAppEventInput!) {\n externalTrackAppEvent(input: $input) {\n void\n }\n}\n";
2
+
3
+ export { TrackAppEvent as default };
@@ -0,0 +1,3 @@
1
+ var InternalTrackAppEvent = "mutation InternalTrackAppEvent($input: TrackAppEventInput!) {\n trackAppEvent(input: $input) {\n void\n }\n}\n\n";
2
+
3
+ export { InternalTrackAppEvent as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/streams-analytics-collector",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",