@streamscloud/streams-analytics-collector 3.0.0 → 4.0.1

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.
@@ -4,11 +4,12 @@ export type TrackingEntityElement = {
4
4
  element: HTMLElement;
5
5
  entity: Entity;
6
6
  relatedEntities?: EntityRelation[] | null;
7
+ attributes?: Record<string, string> | null;
7
8
  };
8
9
  export declare class AppearanceEventsTracker {
9
10
  private viewportVisibilityTracker;
10
11
  private eventsReporter;
11
12
  constructor(viewportVisibilityTracker: ViewportVisibilityTracker, eventsReporter: EventsReporter);
12
- trackElementAppearance({ entity, element, relatedEntities }: TrackingEntityElement): () => void;
13
+ trackElementAppearance({ entity, element, relatedEntities, attributes }: TrackingEntityElement): () => void;
13
14
  untrackElementAppearance(el: HTMLElement): void;
14
15
  }
@@ -7,11 +7,12 @@ class AppearanceEventsTracker {
7
7
  this.viewportVisibilityTracker = viewportVisibilityTracker;
8
8
  this.eventsReporter = eventsReporter;
9
9
  }
10
- trackElementAppearance({ entity, element, relatedEntities }) {
10
+ trackElementAppearance({ entity, element, relatedEntities, attributes }) {
11
11
  this.viewportVisibilityTracker.registerElement(element, getTrackingId(entity), () => this.eventsReporter.reportEvent({
12
12
  entity,
13
13
  eventType: EventType.Appeared,
14
- relatedEntities
14
+ relatedEntities,
15
+ attributes,
15
16
  }));
16
17
  return () => this.viewportVisibilityTracker.unregisterElement(element);
17
18
  }
@@ -3,6 +3,7 @@ export type BatchedMeasurement = {
3
3
  entity: Entity;
4
4
  measurementType: MeasurementType;
5
5
  value: number;
6
+ attributes?: Record<string, string> | null;
6
7
  };
7
8
  export type FailedBatchedMeasurement = {
8
9
  measurement: BatchedMeasurement;
@@ -38,6 +38,7 @@ class MeasurementsBatcher {
38
38
  measurementType: measurement.measurementType,
39
39
  value: measurement.value,
40
40
  relatedEntities: containerRelations,
41
+ attributes: measurement.attributes
41
42
  });
42
43
  succeeded.push(measurement);
43
44
  entitiesInGroup.delete(key);
@@ -82,7 +83,7 @@ function getContainerGroupKey(containers) {
82
83
  }
83
84
  function getContainerRelations(containers) {
84
85
  return normalizeContainers(containers).map((c) => ({
85
- relationType: EntityRelationType.PlacedIn,
86
+ relationType: EntityRelationType.NestedIn,
86
87
  entity: c,
87
88
  }));
88
89
  }
@@ -4,11 +4,12 @@ export type ReportedEvent = {
4
4
  entity: Entity;
5
5
  eventType: EventType;
6
6
  relatedEntities?: EntityRelation[] | null;
7
+ attributes?: Record<string, string> | null;
7
8
  };
8
9
  export declare class EventsReporter {
9
10
  private gqlDataSender;
10
11
  private analyticsSchema;
11
12
  private analyticsMetadata?;
12
13
  constructor(gqlDataSender: GqlDataSender, analyticsSchema: AnalyticsSchema, analyticsMetadata?: AnalyticsMetadata | null);
13
- reportEvent({ entity, eventType, relatedEntities }: ReportedEvent): Promise<void>;
14
+ reportEvent({ entity, eventType, relatedEntities, attributes }: ReportedEvent): Promise<void>;
14
15
  }
@@ -7,7 +7,7 @@ class EventsReporter {
7
7
  this.analyticsSchema = analyticsSchema;
8
8
  this.analyticsMetadata = analyticsMetadata;
9
9
  }
10
- async reportEvent({ entity, eventType, relatedEntities }) {
10
+ async reportEvent({ entity, eventType, relatedEntities, attributes }) {
11
11
  const input = {
12
12
  entityType: entity.type,
13
13
  entityId: entity.id,
@@ -22,6 +22,9 @@ class EventsReporter {
22
22
  ? {
23
23
  id: this.analyticsMetadata.installationId,
24
24
  } : null,
25
+ attributes: attributes
26
+ ? Object.entries(attributes).map(([key, value]) => ({ key, value }))
27
+ : null,
25
28
  };
26
29
  await this.gqlDataSender.send(this.analyticsSchema.reportEvent, { input });
27
30
  }
@@ -5,11 +5,12 @@ export type ReportedMeasurement = {
5
5
  measurementType: MeasurementType;
6
6
  value: number;
7
7
  relatedEntities?: EntityRelation[] | null;
8
+ attributes?: Record<string, string> | null;
8
9
  };
9
10
  export declare class MeasurementsReporter {
10
11
  private gqlDataSender;
11
12
  private analyticsSchema;
12
13
  private analyticsMetadata?;
13
14
  constructor(gqlDataSender: GqlDataSender, analyticsSchema: AnalyticsSchema, analyticsMetadata?: AnalyticsMetadata | null);
14
- reportMeasurement({ entity, measurementType, value, relatedEntities }: ReportedMeasurement): Promise<void>;
15
+ reportMeasurement({ entity, measurementType, value, relatedEntities, attributes }: ReportedMeasurement): Promise<void>;
15
16
  }
@@ -7,7 +7,7 @@ class MeasurementsReporter {
7
7
  this.analyticsSchema = analyticsSchema;
8
8
  this.analyticsMetadata = analyticsMetadata;
9
9
  }
10
- async reportMeasurement({ entity, measurementType, value, relatedEntities }) {
10
+ async reportMeasurement({ entity, measurementType, value, relatedEntities, attributes }) {
11
11
  const input = {
12
12
  entityType: entity.type,
13
13
  entityId: entity.id,
@@ -23,6 +23,9 @@ class MeasurementsReporter {
23
23
  ? {
24
24
  id: this.analyticsMetadata.installationId,
25
25
  } : null,
26
+ attributes: attributes
27
+ ? Object.entries(attributes).map(([key, value]) => ({ key, value }))
28
+ : null,
26
29
  };
27
30
  await this.gqlDataSender.send(this.analyticsSchema.reportMeasurement, { input });
28
31
  }
@@ -25,7 +25,7 @@ export declare enum MeasurementType {
25
25
  Progress = "PROGRESS"
26
26
  }
27
27
  export declare enum EntityRelationType {
28
- PlacedIn = "PLACED_IN"
28
+ NestedIn = "NESTED_IN"
29
29
  }
30
30
  export type AnalyticsSchema = {
31
31
  reportEvent: string;
@@ -52,3 +52,7 @@ export type InstallationInput = {
52
52
  device?: string | null;
53
53
  browser?: string | null;
54
54
  };
55
+ export type KeyValuePair<TKey, TValue> = {
56
+ key: TKey;
57
+ value: TValue;
58
+ };
@@ -29,7 +29,7 @@ var MeasurementType;
29
29
  })(MeasurementType || (MeasurementType = {}));
30
30
  var EntityRelationType;
31
31
  (function (EntityRelationType) {
32
- EntityRelationType["PlacedIn"] = "PLACED_IN";
32
+ EntityRelationType["NestedIn"] = "NESTED_IN";
33
33
  })(EntityRelationType || (EntityRelationType = {}));
34
34
 
35
35
  export { EntityRelationType, EntityType, EventType, MeasurementType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/streams-analytics-collector",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -26,6 +26,9 @@
26
26
  "keywords": [],
27
27
  "author": "StreamsCloud",
28
28
  "description": "",
29
+ "peerDependencies": {
30
+ "@urql/core": "^5.1.1 || ^6.0.0"
31
+ },
29
32
  "devDependencies": {
30
33
  "@typescript-eslint/eslint-plugin": "^8.28.0",
31
34
  "@typescript-eslint/parser": "^8.28.0",
@@ -36,9 +39,7 @@
36
39
  "rollup": "^4.37.0",
37
40
  "rollup-plugin-string": "^3.0.0",
38
41
  "rollup-plugin-typescript2": "^0.36.0",
39
- "typescript": "^5.8.2"
40
- },
41
- "dependencies": {
42
+ "typescript": "^5.8.2",
42
43
  "@urql/core": "^5.1.1"
43
44
  }
44
45
  }
@@ -1,280 +0,0 @@
1
- import type { Client } from "@urql/core";
2
- /**
3
- * AppEventsTracker is a utility class for tracking various user events in StreamsCloud applications
4
- * such as post views, community message views, stream interactions, etc.
5
- */
6
- export declare class AppEventsTracker {
7
- private static reported;
8
- private static playedPercentsByPost;
9
- private static videosByPage;
10
- private static gqlEndpoint;
11
- private static client;
12
- private static organizationId;
13
- private static profileId;
14
- private static useClient;
15
- /**
16
- * Set the GraphQL client for making API calls (for authorized calls)
17
- * @param client - The URQL client instance
18
- */
19
- static setClient(client: Client): void;
20
- /**
21
- * Set the GraphQL endpoint for making API calls (for non-authorized calls)
22
- * @param endpoint - The GraphQL endpoint URL
23
- */
24
- static setEndpoint(endpoint: string): void;
25
- /**
26
- * Set organization ID for non-authorized calls
27
- * @param organizationId - The organization ID
28
- */
29
- static setOrganizationId(organizationId: string): void;
30
- /**
31
- * Set profile ID for non-authorized calls
32
- * @param profileId - The profile ID
33
- */
34
- static setProfileId(profileId: string): void;
35
- /**
36
- * Track the progress of a short video within a page
37
- * @param pageId - The ID of the page containing the video
38
- * @param videoId - The ID of the video
39
- * @param playedPercents - The percentage of the video that has been played
40
- * @param streamId - The ID of the stream containing the video (optional)
41
- */
42
- static trackShortVideoProgress(pageId: string, videoId: string, playedPercents: number, streamId?: string): void;
43
- /**
44
- * Report all video views for a page when it's deactivated
45
- * @param pageId - The ID of the page that's being deactivated
46
- * @param streamId - The ID of the stream containing the page (optional)
47
- */
48
- static reportPageVideoViews(pageId: string, streamId?: string): void;
49
- /**
50
- * Track when a post is opened
51
- * @param postId - The ID of the post
52
- * @param ownerId - The ID of the owner
53
- */
54
- static trackPostOpened(postId: string, ownerId: string): void;
55
- /**
56
- * Track when a post is being played
57
- * @param postId - The ID of the post
58
- * @param playedPercents - The percentage of the post that has been played
59
- * @deprecated Consider using trackShortVideoProgress for better tracking of multiple videos
60
- */
61
- static reportVideoPostPlayingProgress(postId: string, playedPercents: number): void;
62
- /**
63
- * Track when a community message is opened
64
- * @param messageId - The ID of the message
65
- * @param status - The status of the message
66
- */
67
- static trackCommunityMessageOpened(messageId: string, status: string): void;
68
- /**
69
- * Track when a stream tile is shown to the user (basic, immediate call).
70
- * @param streamId - The ID of the stream
71
- */
72
- static trackStreamTileImpression(streamId: string): void;
73
- /**
74
- * Track when a stream tile is shown to the user, using viewport visibility tracking.
75
- * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
76
- * The event is only fired once per streamId per session/visit.
77
- *
78
- * @param el - The DOM element to observe (e.g., the stream tile)
79
- * @param streamId - The unique stream ID for this tile
80
- */
81
- static trackStreamTileImpressionWithVisibility(el: HTMLElement, streamId: string): void;
82
- /**
83
- * Track when a stream tile is clicked
84
- * @param streamId - The ID of the stream
85
- */
86
- static trackStreamTileClick(streamId: string): void;
87
- /**
88
- * Track when a stream is viewed
89
- * @param streamId - The ID of the stream
90
- */
91
- static trackStreamView(streamId: string): void;
92
- /**
93
- * Track the amount of time a user engages with a stream
94
- * @param streamId - The ID of the stream
95
- * @param engagementTimeSeconds - The engagement time in seconds
96
- */
97
- static trackStreamEngagementTime(streamId: string, engagementTimeSeconds: number): void;
98
- /**
99
- * Track how deep a user scrolls in a stream
100
- * @param streamId - The ID of the stream
101
- * @param scrollDepth - The scroll depth (typically a percentage)
102
- */
103
- static trackStreamScrollDepth(streamId: string, scrollDepth: number): void;
104
- /**
105
- * Track when a stream page is viewed
106
- * @param pageId - The ID of the page
107
- * @param streamId - The ID of the stream
108
- */
109
- static trackStreamPageView(pageId: string, streamId: string): void;
110
- /**
111
- * Track when a product in a stream is clicked
112
- * @param productId - The ID of the product
113
- * @param streamId - The ID of the stream
114
- */
115
- static trackStreamProductClicked(productId: string, streamId: string): void;
116
- /**
117
- * Track when a product in a stream is shown to the user (basic, immediate call)
118
- * @param productId - The ID of the product
119
- * @param streamId - The ID of the stream
120
- */
121
- static trackStreamProductImpression(productId: string, streamId: string): void;
122
- /**
123
- * Track when a product in a stream is shown to the user, using viewport visibility tracking.
124
- * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
125
- * The event is only fired once per productId per session/visit.
126
- *
127
- * @param el - The DOM element to observe (e.g., the product element)
128
- * @param productId - The unique product ID for this element
129
- * @param streamId - The ID of the stream
130
- */
131
- static trackStreamProductImpressionWithVisibility(el: HTMLElement, productId: string, streamId: string): void;
132
- /**
133
- * Track when a product in a stream is added to cart
134
- * @param productId - The ID of the product
135
- * @param streamId - The ID of the stream
136
- */
137
- static trackStreamProductAddToCart(productId: string, streamId: string): void;
138
- /**
139
- * Track when a product in a stream is checked out
140
- * @param productId - The ID of the product
141
- * @param streamId - The ID of the stream
142
- */
143
- static trackStreamProductCheckout(productId: string, streamId: string): void;
144
- /**
145
- * Track when a post is closed
146
- * @param postId - The ID of the post
147
- * @param streamId - The ID of the stream
148
- * @deprecated Consider using trackShortVideoProgress and reportPageVideoViews for better tracking of multiple videos
149
- */
150
- static trackClosed(postId: string, streamId: string): void;
151
- /**
152
- * Track when an ad is shown to the user
153
- * @param adId - The ID of the ad
154
- */
155
- static trackAdImpression(adId: string): void;
156
- /**
157
- * Track when an ad is clicked by the user
158
- * @param adId - The ID of the ad
159
- */
160
- static trackAdClick(adId: string): void;
161
- /**
162
- * Track when an ad is shown to the user, using viewport visibility tracking.
163
- * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
164
- * The event is only fired once per adId per session/visit.
165
- *
166
- * @param el - The DOM element to observe (e.g., the ad element)
167
- * @param adId - The unique ad ID for this element
168
- */
169
- static trackAdImpressionWithVisibility(el: HTMLElement, adId: string): void;
170
- /**
171
- * Track when a short video is shown to the user (basic, immediate call)
172
- * @param videoId - The ID of the short video
173
- */
174
- static trackShortVideoImpression(videoId: string): void;
175
- /**
176
- * Track when a short video is shown to the user, using viewport visibility tracking.
177
- * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
178
- * The event is only fired once per videoId per session/visit.
179
- *
180
- * @param el - The DOM element to observe (e.g., the video element)
181
- * @param videoId - The unique video ID for this element
182
- */
183
- static trackShortVideoImpressionWithVisibility(el: HTMLElement, videoId: string): void;
184
- /**
185
- * Track when a short video is viewed by the user
186
- * @param videoId - The ID of the short video
187
- * @param playedPercents - The percentage of the video that was played (optional)
188
- */
189
- static trackShortVideoView(videoId: string): void;
190
- /**
191
- * Track when a product in a short video is clicked
192
- * @param productId - The ID of the product
193
- * @param videoId - The ID of the short video containing the product
194
- */
195
- static trackShortVideoProductClick(productId: string, videoId: string): void;
196
- /**
197
- * Track when a product in a short video is shown to the user (basic, immediate call)
198
- * @param productId - The ID of the product
199
- * @param videoId - The ID of the short video containing the product
200
- */
201
- static trackShortVideoProductImpression(productId: string, videoId: string): void;
202
- /**
203
- * Track when a product in a short video is shown to the user, using viewport visibility tracking.
204
- * The impression event will only be fired if the element becomes visible (at least 50% in viewport).
205
- * The event is only fired once per productId per session/visit.
206
- *
207
- * @param el - The DOM element to observe (e.g., the product element)
208
- * @param productId - The unique product ID for this element
209
- * @param videoId - The ID of the short video containing the product
210
- */
211
- static trackShortVideoProductImpressionWithVisibility(el: HTMLElement, productId: string, videoId: string): void;
212
- /**
213
- * Track when a product in a short video is added to cart
214
- * @param productId - The ID of the product
215
- * @param videoId - The ID of the short video containing the product
216
- */
217
- static trackShortVideoProductAddToCart(productId: string, videoId: string): void;
218
- /**
219
- * Track when a product in a short video is checked out
220
- * @param productId - The ID of the product
221
- * @param videoId - The ID of the short video containing the product
222
- */
223
- static trackShortVideoProductCheckout(productId: string, videoId: string): void;
224
- /**
225
- * Report an app event to the API
226
- * @private
227
- * @param targetId - The ID of the target object
228
- * @param eventType - The type of event
229
- * @param ownerId - The ID of the owner (optional)
230
- * @param value - Additional value for the event (optional)
231
- */
232
- private static reportAppEvent;
233
- /**
234
- * Save an app event to the API
235
- * @private
236
- * @param targetId - The ID of the target object
237
- * @param eventType - The type of event
238
- * @param ownerId - The ID of the owner (optional)
239
- * @param value - Additional value for the event (optional)
240
- */
241
- private static saveAppEvent;
242
- private static queryGql;
243
- }
244
- export declare enum AppEventType {
245
- AdClick = "AD_CLICK",
246
- AdImpression = "AD_IMPRESSION",
247
- CommunityMessageView = "COMMUNITY_MESSAGE_VIEW",
248
- ContributionCreated = "CONTRIBUTION_CREATED",
249
- PostView = "POST_VIEW",
250
- ShortVideoImpression = "SHORT_VIDEO_IMPRESSION",
251
- ShortVideoProductAddToCart = "SHORT_VIDEO_PRODUCT_ADD_TO_CART",
252
- ShortVideoProductCheckout = "SHORT_VIDEO_PRODUCT_CHECKOUT",
253
- ShortVideoProductClick = "SHORT_VIDEO_PRODUCT_CLICK",
254
- ShortVideoProductImpression = "SHORT_VIDEO_PRODUCT_IMPRESSION",
255
- ShortVideoView = "SHORT_VIDEO_VIEW",
256
- StreamEngagementTime = "STREAM_ENGAGEMENT_TIME",
257
- StreamPageView = "STREAM_PAGE_VIEW",
258
- StreamProductAddToCart = "STREAM_PRODUCT_ADD_TO_CART",
259
- StreamProductCheckout = "STREAM_PRODUCT_CHECKOUT",
260
- StreamProductClick = "STREAM_PRODUCT_CLICK",
261
- StreamProductImpression = "STREAM_PRODUCT_IMPRESSION",
262
- StreamScrollDepth = "STREAM_SCROLL_DEPTH",
263
- StreamTileClick = "STREAM_TILE_CLICK",
264
- StreamTileImpression = "STREAM_TILE_IMPRESSION",
265
- StreamView = "STREAM_VIEW"
266
- }
267
- export declare enum CommunityMessageStatus {
268
- Sent = "SENT",
269
- Delivered = "DELIVERED",
270
- Read = "READ",
271
- Failed = "FAILED"
272
- }
273
- export type TrackAppEventInput = {
274
- eventType: AppEventType;
275
- targetId: string;
276
- ownerId?: string;
277
- value?: number;
278
- organizationId?: string;
279
- profileId?: string;
280
- };
@@ -1,15 +0,0 @@
1
- import { type Entity, type MeasurementsReporter, type MeasurementType } from './reporting';
2
- export type TrackingMeasurement = {
3
- entity: Entity;
4
- measurementType: MeasurementType;
5
- value: number;
6
- };
7
- export declare class ContainedEntityMeasurementsTracker {
8
- private measurementsReporter;
9
- private containerEntities;
10
- constructor(measurementsReporter: MeasurementsReporter);
11
- collectEntityMeasurement(containers: Entity[], measurement: TrackingMeasurement): void;
12
- reportGroupedMeasurements(containers: Entity[], onReported?: (measurement: TrackingMeasurement) => void): Promise<void>;
13
- clearContainerEntities(containers: Entity[]): void;
14
- reset(): void;
15
- }
@@ -1,78 +0,0 @@
1
- import { EntityRelationType } from './reporting/types.js';
2
-
3
- class ContainedEntityMeasurementsTracker {
4
- measurementsReporter;
5
- containerEntities = new Map();
6
- constructor(measurementsReporter) {
7
- this.measurementsReporter = measurementsReporter;
8
- }
9
- collectEntityMeasurement(containers, measurement) {
10
- if (containers.length === 0) {
11
- throw new Error('At least one container entity is required.');
12
- }
13
- const groupKey = getContainerGroupKey(containers);
14
- let entitiesInGroup = this.containerEntities.get(groupKey);
15
- if (!entitiesInGroup) {
16
- entitiesInGroup = new Map();
17
- this.containerEntities.set(groupKey, entitiesInGroup);
18
- }
19
- entitiesInGroup.set(getMeasurementKey(measurement), measurement);
20
- }
21
- async reportGroupedMeasurements(containers, onReported) {
22
- if (containers.length === 0) {
23
- throw new Error('At least one container entity is required.');
24
- }
25
- const groupKey = getContainerGroupKey(containers);
26
- const entitiesInGroup = this.containerEntities.get(groupKey);
27
- if (!entitiesInGroup || entitiesInGroup.size === 0) {
28
- return;
29
- }
30
- const containerRelations = getContainerRelations(containers);
31
- try {
32
- await Promise.all(Array.from(entitiesInGroup.values()).map(async (measurement) => {
33
- await this.measurementsReporter.reportMeasurement({
34
- entity: measurement.entity,
35
- measurementType: measurement.measurementType,
36
- value: measurement.value,
37
- relatedEntities: containerRelations,
38
- });
39
- onReported?.(measurement);
40
- }));
41
- }
42
- finally {
43
- this.containerEntities.delete(groupKey);
44
- }
45
- }
46
- clearContainerEntities(containers) {
47
- const groupKey = getContainerGroupKey(containers);
48
- this.containerEntities.delete(groupKey);
49
- }
50
- reset() {
51
- this.containerEntities.clear();
52
- }
53
- }
54
- function getEntityKey(entity) {
55
- return `${entity.type}::${entity.id}`;
56
- }
57
- function getMeasurementKey(container) {
58
- return `${getEntityKey(container.entity)}::${container.measurementType}`;
59
- }
60
- function normalizeContainers(containers) {
61
- const uniq = new Map();
62
- for (const c of containers) {
63
- uniq.set(getEntityKey(c), c);
64
- }
65
- return Array.from(uniq.values()).sort((a, b) => getEntityKey(a).localeCompare(getEntityKey(b)));
66
- }
67
- function getContainerGroupKey(containers) {
68
- const keys = normalizeContainers(containers).map(getEntityKey);
69
- return keys.join('||');
70
- }
71
- function getContainerRelations(containers) {
72
- return normalizeContainers(containers).map((c) => ({
73
- relationType: EntityRelationType.PlacedIn,
74
- entity: c,
75
- }));
76
- }
77
-
78
- export { ContainedEntityMeasurementsTracker };
@@ -1,14 +0,0 @@
1
- import { type AnalyticsMetadata, type EntityType, type EventType, type EntityRelation } from './types';
2
- import type { GqlDataSender } from './gql-data-sender';
3
- export type ReportedEvent = {
4
- entityType: EntityType;
5
- entityId: string;
6
- eventType: EventType;
7
- relatedEntities?: EntityRelation[] | null;
8
- };
9
- export declare class EventsReporter {
10
- private gqlDataSender;
11
- private analyticsMetadata?;
12
- constructor(gqlDataSender: GqlDataSender, analyticsMetadata?: AnalyticsMetadata | null);
13
- reportEvent({ entityType, entityId, eventType, relatedEntities }: ReportedEvent): Promise<void>;
14
- }
@@ -1,27 +0,0 @@
1
- import { ApiMode } from './types.js';
2
- import ReportEvent from './report-event.graphql.js';
3
- import ReportExternalEvent from './report-external-event.graphql.js';
4
-
5
- class EventsReporter {
6
- gqlDataSender;
7
- analyticsMetadata;
8
- constructor(gqlDataSender, analyticsMetadata) {
9
- this.gqlDataSender = gqlDataSender;
10
- this.analyticsMetadata = analyticsMetadata;
11
- }
12
- async reportEvent({ entityType, entityId, eventType, relatedEntities }) {
13
- const input = {
14
- entityType,
15
- entityId,
16
- eventType,
17
- relatedEntities,
18
- installation: this.analyticsMetadata?.installationId
19
- ? {
20
- id: this.analyticsMetadata.installationId,
21
- } : null
22
- };
23
- await this.gqlDataSender.send((apiMode) => apiMode === ApiMode.Internal ? ReportEvent : ReportExternalEvent, { input });
24
- }
25
- }
26
-
27
- export { EventsReporter };
@@ -1,16 +0,0 @@
1
- import type { Client } from '@urql/core';
2
- import type { ApiMode } from './types';
3
- export type GqlDataSenderOptions = {
4
- client: Client;
5
- mode: ApiMode;
6
- } | {
7
- endpoint: string;
8
- mode: ApiMode;
9
- };
10
- export declare class GqlDataSender {
11
- private gqlEndpoint;
12
- private client;
13
- private apiMode;
14
- constructor(options: GqlDataSenderOptions);
15
- send(querySelector: (apiMode: ApiMode) => string, variables?: object): Promise<void>;
16
- }
@@ -1,38 +0,0 @@
1
- class GqlDataSender {
2
- gqlEndpoint = null;
3
- client = null;
4
- apiMode;
5
- constructor(options) {
6
- if ('client' in options) {
7
- this.client = options.client;
8
- this.gqlEndpoint = null;
9
- }
10
- else {
11
- this.gqlEndpoint = options.endpoint;
12
- this.client = null;
13
- }
14
- this.apiMode = options.mode;
15
- }
16
- async send(querySelector, variables) {
17
- const query = querySelector(this.apiMode);
18
- if (this.gqlEndpoint) {
19
- await sendGqlBeacon(this.gqlEndpoint, query, variables);
20
- }
21
- else if (this.client) {
22
- await this.client.mutation(query, variables).toPromise();
23
- }
24
- else {
25
- console.error('EventsReporter not properly initialized.');
26
- }
27
- }
28
- }
29
- async function sendGqlBeacon(endpoint, query, variables) {
30
- const body = JSON.stringify({ query, variables });
31
- const blob = new Blob([body], { type: 'application/json' });
32
- const accepted = navigator.sendBeacon(endpoint, blob);
33
- if (!accepted) {
34
- throw new Error('Failed to queue analytics beacon.');
35
- }
36
- }
37
-
38
- export { GqlDataSender };
@@ -1,15 +0,0 @@
1
- import { type AnalyticsMetadata, type EntityType, type MeasurementType, type EntityRelation } from './types';
2
- import type { GqlDataSender } from './gql-data-sender';
3
- export type ReportedMeasurement = {
4
- entityType: EntityType;
5
- entityId: string;
6
- measurementType: MeasurementType;
7
- value: number;
8
- relatedEntities?: EntityRelation[] | null;
9
- };
10
- export declare class MeasurementsReporter {
11
- private gqlDataSender;
12
- private analyticsMetadata?;
13
- constructor(gqlDataSender: GqlDataSender, analyticsMetadata?: AnalyticsMetadata | null);
14
- reportMeasurement({ entityType, entityId, measurementType, value, relatedEntities }: ReportedMeasurement): Promise<void>;
15
- }
@@ -1,28 +0,0 @@
1
- import { ApiMode } from './types.js';
2
- import ReportMeasurement from './report-measurement.graphql.js';
3
- import ReportExternalMeasurement from './report-external-measurement.graphql.js';
4
-
5
- class MeasurementsReporter {
6
- gqlDataSender;
7
- analyticsMetadata;
8
- constructor(gqlDataSender, analyticsMetadata) {
9
- this.gqlDataSender = gqlDataSender;
10
- this.analyticsMetadata = analyticsMetadata;
11
- }
12
- async reportMeasurement({ entityType, entityId, measurementType, value, relatedEntities }) {
13
- const input = {
14
- entityType,
15
- entityId,
16
- measurementType,
17
- value,
18
- relatedEntities,
19
- installation: this.analyticsMetadata?.installationId
20
- ? {
21
- id: this.analyticsMetadata.installationId,
22
- } : null,
23
- };
24
- await this.gqlDataSender.send((apiMode) => apiMode === ApiMode.Internal ? ReportMeasurement : ReportExternalMeasurement, { input });
25
- }
26
- }
27
-
28
- export { MeasurementsReporter };
@@ -1,3 +0,0 @@
1
- var ReportEvent = "mutation ReportEvent($input: ReportEventInput!) {\n reportEvent(input: $input) {\n void\n }\n}\n";
2
-
3
- export { ReportEvent as default };
@@ -1,3 +0,0 @@
1
- var ReportExternalEvent = "mutation ReportExternalEvent($input: ReportExternalEventInput!) {\n reportExternalEvent(input: $input) {\n void\n }\n}\n";
2
-
3
- export { ReportExternalEvent as default };
@@ -1,3 +0,0 @@
1
- var ReportExternalMeasurement = "mutation ReportExternalMeasurement($input: ReportExternalMeasurementInput!) {\n reportExternalMeasurement(input: $input) {\n void\n }\n}\n";
2
-
3
- export { ReportExternalMeasurement as default };
@@ -1,3 +0,0 @@
1
- var ReportMeasurement = "mutation ReportMeasurement($input: ReportMeasurementInput!) {\n reportMeasurement(input: $input) {\n void\n }\n}\n";
2
-
3
- export { ReportMeasurement as default };
@@ -1,3 +0,0 @@
1
- var ReportEvent = "mutation ReportEvent($input: ReportEventInput!) {\n reportEvent(input: $input) {\n void\n }\n}\n";
2
-
3
- export { ReportEvent as default };
@@ -1,3 +0,0 @@
1
- var ReportExternalEvent = "mutation ReportExternalEvent($input: ReportExternalEventInput!) {\n reportExternalEvent(input: $input) {\n void\n }\n}\n";
2
-
3
- export { ReportExternalEvent as default };
@@ -1,3 +0,0 @@
1
- var ReportExternalMeasurement = "mutation ReportExternalMeasurement($input: ReportExternalMeasurementInput!) {\n reportExternalMeasurement(input: $input) {\n void\n }\n}\n";
2
-
3
- export { ReportExternalMeasurement as default };
@@ -1,3 +0,0 @@
1
- var ReportMeasurement = "mutation ReportMeasurement($input: ReportMeasurementInput!) {\n reportMeasurement(input: $input) {\n void\n }\n}\n";
2
-
3
- export { ReportMeasurement as default };
package/dist/types.d.ts DELETED
File without changes
package/dist/types.js DELETED
@@ -1,39 +0,0 @@
1
- var ApiMode;
2
- (function (ApiMode) {
3
- ApiMode["Internal"] = "internal";
4
- ApiMode["External"] = "external";
5
- })(ApiMode || (ApiMode = {}));
6
- var EntityType;
7
- (function (EntityType) {
8
- EntityType["Article"] = "ARTICLE";
9
- EntityType["Audio"] = "AUDIO";
10
- EntityType["Event"] = "EVENT";
11
- EntityType["Media"] = "MEDIA";
12
- EntityType["Moment"] = "MOMENT";
13
- EntityType["Link"] = "LINK";
14
- EntityType["ShortVideo"] = "SHORT_VIDEO";
15
- EntityType["Text"] = "TEXT";
16
- EntityType["Video"] = "VIDEO";
17
- EntityType["Product"] = "PRODUCT";
18
- EntityType["Stream"] = "STREAM";
19
- EntityType["StreamPage"] = "STREAM_PAGE";
20
- EntityType["Ad"] = "AD";
21
- })(EntityType || (EntityType = {}));
22
- var EventType;
23
- (function (EventType) {
24
- EventType["Appeared"] = "APPEARED";
25
- EventType["Viewed"] = "VIEWED";
26
- EventType["Clicked"] = "CLICKED";
27
- })(EventType || (EventType = {}));
28
- var MeasurementType;
29
- (function (MeasurementType) {
30
- MeasurementType["ScrollDepth"] = "SCROLL_DEPTH";
31
- MeasurementType["EngagementTime"] = "ENGAGEMENT_TIME";
32
- MeasurementType["Progress"] = "PROGRESS";
33
- })(MeasurementType || (MeasurementType = {}));
34
- var EntityRelationType;
35
- (function (EntityRelationType) {
36
- EntityRelationType["PlacedIn"] = "PLACED_IN";
37
- })(EntityRelationType || (EntityRelationType = {}));
38
-
39
- export { ApiMode, EntityRelationType, EntityType, EventType, MeasurementType };