@streamscloud/streams-analytics-collector 2.0.3 → 2.0.5
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 +1 -1
- package/dist/analytics/app-events-tracker.js +13 -14
- package/dist/analytics/index.d.ts +3 -3
- package/dist/external-analytics.graphql.js +3 -0
- package/dist/index.d.ts +2 -2
- package/dist/internal-analytics.graphql.js +3 -0
- 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,5 +1,6 @@
|
|
|
1
1
|
import { AppEventType, CommunityMessageStatus } from './types.js';
|
|
2
|
-
import
|
|
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
|
/**
|
|
@@ -11,7 +12,7 @@ class AppEventsTracker {
|
|
|
11
12
|
static playedPercentsByPost = new Map();
|
|
12
13
|
// Store video data by page ID to handle multiple videos per page
|
|
13
14
|
static videosByPage = new Map();
|
|
14
|
-
static gqlEndpoint =
|
|
15
|
+
static gqlEndpoint = "";
|
|
15
16
|
static client;
|
|
16
17
|
static organizationId;
|
|
17
18
|
static profileId;
|
|
@@ -62,7 +63,7 @@ class AppEventsTracker {
|
|
|
62
63
|
// Only store the maximum percentage in case of looping videos
|
|
63
64
|
const pageVideos = this.videosByPage.get(pageId);
|
|
64
65
|
if (pageVideos) {
|
|
65
|
-
const videoKey = `${videoId}|${streamId ||
|
|
66
|
+
const videoKey = `${videoId}|${streamId || ""}`;
|
|
66
67
|
const currentMaxPercent = pageVideos.get(videoKey) || 0;
|
|
67
68
|
// Store only the maximum played percentage value
|
|
68
69
|
// This ensures we don't decrease progress when video loops
|
|
@@ -79,7 +80,7 @@ class AppEventsTracker {
|
|
|
79
80
|
if (pageVideos) {
|
|
80
81
|
// Report all video views for this page
|
|
81
82
|
pageVideos.forEach((playedPercents, videoKey) => {
|
|
82
|
-
const [videoId, videoStreamId] = videoKey.split(
|
|
83
|
+
const [videoId, videoStreamId] = videoKey.split("|");
|
|
83
84
|
this.reportAppEvent(videoId, AppEventType.ShortVideoView, videoStreamId || streamId, playedPercents);
|
|
84
85
|
});
|
|
85
86
|
// Clean up the tracking data for this page
|
|
@@ -258,7 +259,7 @@ class AppEventsTracker {
|
|
|
258
259
|
eventType,
|
|
259
260
|
targetId,
|
|
260
261
|
ownerId: ownerId || undefined,
|
|
261
|
-
value: value || undefined
|
|
262
|
+
value: value || undefined,
|
|
262
263
|
};
|
|
263
264
|
// Add organization and profile IDs for non-authorized calls if they exist
|
|
264
265
|
if (!this.useClient) {
|
|
@@ -273,16 +274,14 @@ class AppEventsTracker {
|
|
|
273
274
|
// Choose between client and direct endpoint modes
|
|
274
275
|
if (this.useClient) {
|
|
275
276
|
if (!this.client) {
|
|
276
|
-
console.warn(
|
|
277
|
+
console.warn("An attempt to save app event without initializing GraphQL client detected");
|
|
277
278
|
return;
|
|
278
279
|
}
|
|
279
|
-
await this.client
|
|
280
|
-
.mutation(TrackAppEvent, { input })
|
|
281
|
-
.toPromise();
|
|
280
|
+
await this.client.mutation(InternalTrackAppEvent, { input }).toPromise();
|
|
282
281
|
}
|
|
283
282
|
else {
|
|
284
283
|
if (!this.gqlEndpoint) {
|
|
285
|
-
console.warn(
|
|
284
|
+
console.warn("An attempt to save app event without initializing GraphQL endpoint detected");
|
|
286
285
|
return;
|
|
287
286
|
}
|
|
288
287
|
await this.queryGql(TrackAppEvent, { input });
|
|
@@ -290,14 +289,14 @@ class AppEventsTracker {
|
|
|
290
289
|
}
|
|
291
290
|
static queryGql = async (query, variables) => {
|
|
292
291
|
const response = await fetch(this.gqlEndpoint, {
|
|
293
|
-
method:
|
|
292
|
+
method: "POST",
|
|
294
293
|
headers: {
|
|
295
|
-
|
|
294
|
+
"Content-Type": "application/json",
|
|
296
295
|
},
|
|
297
296
|
body: JSON.stringify({
|
|
298
297
|
query,
|
|
299
|
-
variables
|
|
300
|
-
})
|
|
298
|
+
variables,
|
|
299
|
+
}),
|
|
301
300
|
});
|
|
302
301
|
const gql = await response.json();
|
|
303
302
|
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";
|
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";
|