@streamscloud/streams-analytics-collector 2.0.2 → 2.0.4

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.
@@ -65,7 +65,7 @@ class ViewportVisibilityTracker {
65
65
  // Try to get streamId from map or from data attribute
66
66
  let streamId = Array.from(this.observedElements.entries()).find(([, v]) => v === el)?.[0];
67
67
  if (!streamId) {
68
- streamId = el.getAttribute('data-stream-id') || undefined;
68
+ streamId = el.getAttribute("data-stream-id") || undefined;
69
69
  }
70
70
  if (!streamId)
71
71
  continue;
@@ -94,10 +94,10 @@ class ViewportVisibilityTracker {
94
94
  if (!el)
95
95
  return false;
96
96
  const rect = el.getBoundingClientRect();
97
- const windowHeight = (window.innerHeight || document.documentElement.clientHeight);
98
- const windowWidth = (window.innerWidth || document.documentElement.clientWidth);
99
- const vertInView = (rect.top <= windowHeight * 0.5) && ((rect.top + rect.height * 0.5) >= 0);
100
- const horInView = (rect.left <= windowWidth * 0.5) && ((rect.left + rect.width * 0.5) >= 0);
97
+ const windowHeight = window.innerHeight || document.documentElement.clientHeight;
98
+ const windowWidth = window.innerWidth || document.documentElement.clientWidth;
99
+ const vertInView = rect.top <= windowHeight * 0.5 && rect.top + rect.height * 0.5 >= 0;
100
+ const horInView = rect.left <= windowWidth * 0.5 && rect.left + rect.width * 0.5 >= 0;
101
101
  return vertInView && horInView;
102
102
  }
103
103
  /**
@@ -1,4 +1,4 @@
1
- import type { Client } from '@urql/core';
1
+ import type { Client } from "@urql/core";
2
2
  /**
3
3
  * AppEventsTracker is a utility class for tracking various user events in StreamsCloud applications
4
4
  * such as post views, community message views, stream interactions, etc.
@@ -17,6 +17,7 @@ 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;
20
21
  /**
21
22
  * Set the GraphQL endpoint for making API calls (for non-authorized calls)
22
23
  * @param endpoint - The GraphQL endpoint URL
@@ -1,5 +1,5 @@
1
1
  import { AppEventType, CommunityMessageStatus } from './types.js';
2
- import ExternalTrackAppEvent from '../analytics.graphql.js';
2
+ import TrackAppEvent from '../analytics.graphql.js';
3
3
  import { ViewportVisibilityTracker } from './ViewportVisibilityTracker.js';
4
4
 
5
5
  /**
@@ -11,7 +11,7 @@ class AppEventsTracker {
11
11
  static playedPercentsByPost = new Map();
12
12
  // Store video data by page ID to handle multiple videos per page
13
13
  static videosByPage = new Map();
14
- static gqlEndpoint = '';
14
+ static gqlEndpoint = "";
15
15
  static client;
16
16
  static organizationId;
17
17
  static profileId;
@@ -24,6 +24,10 @@ class AppEventsTracker {
24
24
  this.client = client;
25
25
  this.useClient = true;
26
26
  }
27
+ static setClientNew(client) {
28
+ this.client = client;
29
+ this.useClient = true;
30
+ }
27
31
  /**
28
32
  * Set the GraphQL endpoint for making API calls (for non-authorized calls)
29
33
  * @param endpoint - The GraphQL endpoint URL
@@ -62,7 +66,7 @@ class AppEventsTracker {
62
66
  // Only store the maximum percentage in case of looping videos
63
67
  const pageVideos = this.videosByPage.get(pageId);
64
68
  if (pageVideos) {
65
- const videoKey = `${videoId}|${streamId || ''}`;
69
+ const videoKey = `${videoId}|${streamId || ""}`;
66
70
  const currentMaxPercent = pageVideos.get(videoKey) || 0;
67
71
  // Store only the maximum played percentage value
68
72
  // This ensures we don't decrease progress when video loops
@@ -79,7 +83,7 @@ class AppEventsTracker {
79
83
  if (pageVideos) {
80
84
  // Report all video views for this page
81
85
  pageVideos.forEach((playedPercents, videoKey) => {
82
- const [videoId, videoStreamId] = videoKey.split('|');
86
+ const [videoId, videoStreamId] = videoKey.split("|");
83
87
  this.reportAppEvent(videoId, AppEventType.ShortVideoView, videoStreamId || streamId, playedPercents);
84
88
  });
85
89
  // Clean up the tracking data for this page
@@ -258,7 +262,7 @@ class AppEventsTracker {
258
262
  eventType,
259
263
  targetId,
260
264
  ownerId: ownerId || undefined,
261
- value: value || undefined
265
+ value: value || undefined,
262
266
  };
263
267
  // Add organization and profile IDs for non-authorized calls if they exist
264
268
  if (!this.useClient) {
@@ -273,31 +277,29 @@ class AppEventsTracker {
273
277
  // Choose between client and direct endpoint modes
274
278
  if (this.useClient) {
275
279
  if (!this.client) {
276
- console.warn('An attempt to save app event without initializing GraphQL client detected');
280
+ console.warn("An attempt to save app event without initializing GraphQL client detected");
277
281
  return;
278
282
  }
279
- await this.client
280
- .mutation(ExternalTrackAppEvent, { input })
281
- .toPromise();
283
+ await this.client.mutation(TrackAppEvent, { input }).toPromise();
282
284
  }
283
285
  else {
284
286
  if (!this.gqlEndpoint) {
285
- console.warn('An attempt to save app event without initializing GraphQL endpoint detected');
287
+ console.warn("An attempt to save app event without initializing GraphQL endpoint detected");
286
288
  return;
287
289
  }
288
- await this.queryGql(ExternalTrackAppEvent, { input });
290
+ await this.queryGql(TrackAppEvent, { input });
289
291
  }
290
292
  }
291
293
  static queryGql = async (query, variables) => {
292
294
  const response = await fetch(this.gqlEndpoint, {
293
- method: 'POST',
295
+ method: "POST",
294
296
  headers: {
295
- 'Content-Type': 'application/json'
297
+ "Content-Type": "application/json",
296
298
  },
297
299
  body: JSON.stringify({
298
300
  query,
299
- variables
300
- })
301
+ variables,
302
+ }),
301
303
  });
302
304
  const gql = await response.json();
303
305
  if (!gql.data) {
@@ -1,3 +1,3 @@
1
- export { AppEventsTracker } from './app-events-tracker';
2
- export { AppEventType, CommunityMessageStatus, type TrackAppEventInput } from './types';
3
- export * from './ViewportVisibilityTracker';
1
+ export { AppEventsTracker } from "./app-events-tracker";
2
+ export { AppEventType, CommunityMessageStatus, type TrackAppEventInput, } from "./types";
3
+ export * from "./ViewportVisibilityTracker";
@@ -1,3 +1,3 @@
1
- var ExternalTrackAppEvent = "mutation ExternalTrackAppEvent($input: ExternalTrackAppEventInput!) {\n externalTrackAppEvent(input: $input) {\n void\n }\n}\n\nmutation TrackAppEvent($input: TrackAppEventInput!) {\n trackAppEvent(input: $input) {\n void\n }\n}\n";
1
+ var TrackAppEvent = "mutation TrackAppEvent($input: ExternalTrackAppEventInput!) {\n externalTrackAppEvent(input: $input) {\n void\n }\n}\n\nmutation InternalTrackAppEvent($input: TrackAppEventInput!) {\n trackAppEvent(input: $input) {\n void\n }\n}\n";
2
2
 
3
- export { ExternalTrackAppEvent as default };
3
+ export { TrackAppEvent as default };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * as Types from './types';
2
- export { AppEventsTracker, AppEventType, CommunityMessageStatus } from './analytics';
1
+ export * as Types from "./types";
2
+ export { AppEventsTracker, AppEventType, CommunityMessageStatus, } from "./analytics";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/streams-analytics-collector",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",