@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.
- package/dist/analytics/ViewportVisibilityTracker.js +5 -5
- package/dist/analytics/app-events-tracker.d.ts +2 -1
- package/dist/analytics/app-events-tracker.js +17 -15
- package/dist/analytics/index.d.ts +3 -3
- package/dist/analytics.graphql.js +2 -2
- package/dist/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -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(
|
|
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 =
|
|
98
|
-
const windowWidth =
|
|
99
|
-
const vertInView =
|
|
100
|
-
const horInView =
|
|
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
|
|
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
|
|
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(
|
|
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(
|
|
287
|
+
console.warn("An attempt to save app event without initializing GraphQL endpoint detected");
|
|
286
288
|
return;
|
|
287
289
|
}
|
|
288
|
-
await this.queryGql(
|
|
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:
|
|
295
|
+
method: "POST",
|
|
294
296
|
headers: {
|
|
295
|
-
|
|
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
|
|
2
|
-
export { AppEventType, CommunityMessageStatus, type TrackAppEventInput } from
|
|
3
|
-
export * from
|
|
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
|
|
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 {
|
|
3
|
+
export { TrackAppEvent as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * as Types from
|
|
2
|
-
export { AppEventsTracker, AppEventType, CommunityMessageStatus } from
|
|
1
|
+
export * as Types from "./types";
|
|
2
|
+
export { AppEventsTracker, AppEventType, CommunityMessageStatus, } from "./analytics";
|