@ogcio/analytics-sdk 0.0.1-beta.2 → 0.0.1-beta.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.
Files changed (50) hide show
  1. package/dist/base/base-client.d.ts +2 -7
  2. package/dist/base/base-client.d.ts.map +1 -1
  3. package/dist/base/base-client.js +3 -15
  4. package/dist/base/base-client.js.map +1 -0
  5. package/{types.d.ts → dist/browser-types.d.ts} +1 -1
  6. package/dist/index.d.ts +403 -1139
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +319 -254
  9. package/dist/index.js.map +1 -0
  10. package/dist/matomo/helpers.d.ts +8 -1
  11. package/dist/matomo/helpers.d.ts.map +1 -1
  12. package/dist/matomo/helpers.js +2 -1
  13. package/dist/matomo/helpers.js.map +1 -0
  14. package/dist/matomo/types.d.ts +2 -1
  15. package/dist/matomo/types.d.ts.map +1 -1
  16. package/dist/matomo/types.js +1 -0
  17. package/dist/matomo/types.js.map +1 -0
  18. package/dist/schema.d.ts +84 -444
  19. package/dist/schema.d.ts.map +1 -1
  20. package/dist/schema.js +1 -0
  21. package/dist/schema.js.map +1 -0
  22. package/dist/support-files/auth/index.js +1 -0
  23. package/dist/support-files/auth/index.js.map +1 -0
  24. package/dist/support-files/auth/types.d.ts +1 -1
  25. package/dist/support-files/auth/types.d.ts.map +1 -1
  26. package/dist/support-files/auth/types.js +1 -0
  27. package/dist/support-files/auth/types.js.map +1 -0
  28. package/dist/support-files/building-blocks-sdk.d.ts +1 -1
  29. package/dist/support-files/building-blocks-sdk.d.ts.map +1 -1
  30. package/dist/support-files/building-blocks-sdk.js +1 -0
  31. package/dist/support-files/building-blocks-sdk.js.map +1 -0
  32. package/dist/utils/index.js +1 -0
  33. package/dist/utils/index.js.map +1 -0
  34. package/package.json +22 -11
  35. package/examples/environment.d.ts +0 -11
  36. package/examples/index.ts +0 -201
  37. package/examples/tsconfig.json +0 -15
  38. package/src/base/base-client.ts +0 -172
  39. package/src/index.test.ts +0 -92
  40. package/src/index.ts +0 -543
  41. package/src/matomo/helpers.ts +0 -115
  42. package/src/matomo/types.ts +0 -64
  43. package/src/schema.ts +0 -1491
  44. package/src/support-files/auth/index.ts +0 -116
  45. package/src/support-files/auth/types.ts +0 -38
  46. package/src/support-files/building-blocks-sdk.ts +0 -32
  47. package/src/utils/index.test.ts +0 -46
  48. package/src/utils/index.ts +0 -20
  49. package/test-report.xml +0 -181
  50. package/tsconfig.json +0 -18
package/dist/index.js CHANGED
@@ -1,28 +1,27 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
1
  import { isBrowser } from "./utils/index.js";
8
- import { getTracker, initMatomoArray, initTracker, push, } from "./matomo/helpers.js";
2
+ import { getTracker, initMatomoArray, initTracker, MatomoConstants, push, } from "./matomo/helpers.js";
9
3
  export * from "./support-files/auth/index.js";
10
4
  // Since Analytics is a client of the Building-Blocks-SDK, we need to temporarily copy and import the base client from the Building-Blocks-SDK
11
5
  // in the future, we should move the base client to a base-building-blocks package, in order to avoid circular dependencies and copy-pasting code
12
- import BaseClient, { ANALYTICS, needsBackend, } from "./base/base-client.js";
6
+ import BaseClient, { ANALYTICS, } from "./base/base-client.js";
7
+ const DIMENSION_PREFIX = "dimension";
13
8
  export class Analytics extends BaseClient {
14
9
  serviceName = ANALYTICS;
15
- organizationId;
16
10
  matomoToken;
17
11
  isDryRun = false;
18
12
  isOptOut = false;
19
13
  trackingWebsiteId;
20
14
  trackingMetadata;
15
+ trackingContext;
16
+ // Variables used on client side only
17
+ organizationId;
21
18
  websiteConfiguration;
22
19
  websiteConfigurationPromise;
23
- constructor({ trackingWebsiteId, organizationId, matomoToken, ...baseApiClientOptions }) {
20
+ constructor({ trackingWebsiteId, organizationId, matomoToken, trackingContext, trackingMetadata, ...baseApiClientOptions }) {
24
21
  super(baseApiClientOptions);
25
22
  this.organizationId = organizationId;
23
+ this.trackingMetadata = trackingMetadata;
24
+ this.trackingContext = trackingContext;
26
25
  if (matomoToken) {
27
26
  this.setMatomoToken(matomoToken);
28
27
  }
@@ -37,7 +36,7 @@ export class Analytics extends BaseClient {
37
36
  if (!this.organizationId) {
38
37
  throw new Error("Organization ID is not set");
39
38
  }
40
- const { data } = await this.getWebsiteById(websiteId, {
39
+ const { data } = await this.administration.getWebsiteById(websiteId, {
41
40
  org_id: this.organizationId,
42
41
  });
43
42
  if (!data)
@@ -49,12 +48,7 @@ export class Analytics extends BaseClient {
49
48
  request.headers.set(headerTokenName, this.matomoToken || "");
50
49
  return request;
51
50
  }
52
- setMatomoToken(matomoToken) {
53
- this.client.eject({ onRequest: this.matomoOnRequestMiddleware.bind(this) });
54
- this.matomoToken = matomoToken;
55
- this.client.use({ onRequest: this.matomoOnRequestMiddleware.bind(this) });
56
- }
57
- clientRequest = async (promise) => {
51
+ async clientRequest(promise) {
58
52
  if (this.isDryRun) {
59
53
  console.warn("Dry run is enabled, skipping request");
60
54
  return { data: undefined, error: undefined };
@@ -68,16 +62,131 @@ export class Analytics extends BaseClient {
68
62
  return { data: result.data, error: result.error };
69
63
  }
70
64
  catch (error) {
71
- console.error("Error tracking event", error);
65
+ console.error("Error making request", error);
72
66
  return { error, data: undefined };
73
67
  }
74
- };
68
+ }
69
+ async ensureWebsiteConfiguration() {
70
+ try {
71
+ await this.websiteConfigurationPromise;
72
+ }
73
+ catch (error) {
74
+ console.error("Error retrieving website configuration", error);
75
+ }
76
+ if (!this.websiteConfiguration) {
77
+ throw new Error("Website configuration cannot be retrieved");
78
+ }
79
+ }
80
+ async trackPush(eventName, eventArguments, siteIds, eventContext) {
81
+ await this.ensureWebsiteConfiguration();
82
+ // validate siteIds based on website configuration
83
+ if (siteIds?.length) {
84
+ const validSiteIds = this.websiteConfiguration?.site_ids;
85
+ if (!validSiteIds?.length) {
86
+ console.error("No valid site IDs found in website configuration");
87
+ return { error: "MISSING_SITE_IDS" };
88
+ }
89
+ siteIds.forEach((siteId) => {
90
+ if (!validSiteIds.includes(siteId)) {
91
+ console.error(`Invalid site ID: ${siteId}. Valid site IDs are: ${validSiteIds.join(", ")}`);
92
+ return { error: "INVALID_SITE_IDS" };
93
+ }
94
+ });
95
+ }
96
+ if (this.isDryRun) {
97
+ console.warn("Dry run is enabled, skipping request");
98
+ return;
99
+ }
100
+ if (this.isOptOut) {
101
+ console.warn("Opt out is enabled, skipping request");
102
+ return;
103
+ }
104
+ // merge of global trackingContext and trackPush eventContext
105
+ const context = {
106
+ ...this.trackingContext,
107
+ ...eventContext,
108
+ customDimensions: {
109
+ ...this.trackingContext?.customDimensions,
110
+ ...eventContext?.customDimensions,
111
+ },
112
+ };
113
+ if (context?.userId) {
114
+ push(["setUserId", context.userId]);
115
+ }
116
+ else {
117
+ push(["resetUserId"]);
118
+ }
119
+ if (context?.customDimensions) {
120
+ const configuredDimensions = this.websiteConfiguration?.custom_dimensions;
121
+ // Check if website has any custom dimensions configured
122
+ if (!configuredDimensions) {
123
+ console.warn(`Warning: Cannot set custom dimensions - no dimensions configured for website ${this.trackingWebsiteId}`);
124
+ }
125
+ // Validate each dimension being set exists in configuration
126
+ const providedDimensions = Object.keys(context.customDimensions);
127
+ const validDimensionKeys = Object.keys(configuredDimensions);
128
+ for (const dimensionKey of providedDimensions) {
129
+ if (!validDimensionKeys.includes(dimensionKey)) {
130
+ console.warn(`Invalid dimension "${dimensionKey}" for website ${this.trackingWebsiteId}. ` +
131
+ `Valid dimensions: [${validDimensionKeys.join(", ")}]`);
132
+ }
133
+ }
134
+ for (const [key, value] of Object.entries(context.customDimensions)) {
135
+ const dimensionId = parseInt(key.replace(DIMENSION_PREFIX, ""));
136
+ push(["setCustomDimension", dimensionId, value]);
137
+ }
138
+ }
139
+ // if there are no siteIds, we use push() for direct tracking across all configured site IDs
140
+ if (!siteIds?.length)
141
+ return push([eventName, ...eventArguments]);
142
+ // if there are siteIds, we need to initialize individual trackers for each siteId and track the event separately
143
+ const trackerEndpoint = `${this.websiteConfiguration.tracker_url}/${this.websiteConfiguration.bypass_adblockers
144
+ ? MatomoConstants.TrackerBypass
145
+ : MatomoConstants.Tracker}`;
146
+ try {
147
+ for (const siteId of siteIds.map(String)) {
148
+ const matomoTracker = getTracker(trackerEndpoint, siteId);
149
+ matomoTracker[eventName](...eventArguments);
150
+ }
151
+ return { data: "success" };
152
+ }
153
+ catch (error) {
154
+ console.error("Error tracking event", error);
155
+ return { error };
156
+ }
157
+ }
158
+ async trackBackendAction(params) {
159
+ this.checkBaseUrlAndToken();
160
+ if (!this.trackingWebsiteId) {
161
+ throw new Error("Tracking website ID is not set");
162
+ }
163
+ const { url, data, generateCode } = params;
164
+ return this.clientRequest(this.client.POST(url, {
165
+ params: {
166
+ path: {
167
+ id: this.trackingWebsiteId,
168
+ },
169
+ query: {
170
+ code: generateCode,
171
+ },
172
+ },
173
+ body: {
174
+ ...data,
175
+ ...this.trackingMetadata,
176
+ },
177
+ }));
178
+ }
179
+ setMatomoToken(matomoToken) {
180
+ this.client.eject({ onRequest: this.matomoOnRequestMiddleware.bind(this) });
181
+ this.matomoToken = matomoToken;
182
+ this.client.use({ onRequest: this.matomoOnRequestMiddleware.bind(this) });
183
+ }
75
184
  /*
76
185
  * Set the tracking website ID and retrieve the website configuration.
77
186
  */
78
187
  setTrackingWebsiteId(websiteId) {
79
188
  this.trackingWebsiteId = websiteId;
80
- if (this.organizationId) {
189
+ if (isBrowser() && this.organizationId) {
81
190
  // We intentionally don't await the promise here to allow for non-blocking initialization.
82
191
  // The website configuration will be ensured before any client-tracking operations in the `ensureWebsiteConfiguration` method.
83
192
  this.websiteConfigurationPromise =
@@ -93,6 +202,37 @@ export class Analytics extends BaseClient {
93
202
  getTrackingMetadata() {
94
203
  return this.trackingMetadata;
95
204
  }
205
+ setTrackingContext(context) {
206
+ this.clearTrackingContext();
207
+ if (isBrowser() && context.customDimensions) {
208
+ for (const [dimensionId, value] of Object.entries(context.customDimensions)) {
209
+ push([
210
+ "setCustomDimension",
211
+ dimensionId.replace(DIMENSION_PREFIX, ""),
212
+ value,
213
+ ]);
214
+ }
215
+ }
216
+ // Deep copy to avoid mutation of original context
217
+ this.trackingContext = structuredClone(context);
218
+ }
219
+ clearTrackingContext() {
220
+ if (isBrowser()) {
221
+ push(["resetUserId"]);
222
+ if (this.trackingContext?.customDimensions) {
223
+ for (const dimensionId of Object.keys(this.trackingContext.customDimensions)) {
224
+ push([
225
+ "deleteCustomDimension",
226
+ dimensionId.replace(DIMENSION_PREFIX, ""),
227
+ ]);
228
+ }
229
+ }
230
+ }
231
+ this.trackingContext = undefined;
232
+ }
233
+ getTrackingContext() {
234
+ return this.trackingContext;
235
+ }
96
236
  /*
97
237
  * The dryRun flag, when set, prevents any data from being sent to the API.
98
238
  * This is useful for testing/debugging purposes.
@@ -119,17 +259,6 @@ export class Analytics extends BaseClient {
119
259
  this.isDryRun = config.dryRun;
120
260
  this.isOptOut = config.optOut;
121
261
  }
122
- async ensureWebsiteConfiguration() {
123
- try {
124
- await this.websiteConfigurationPromise;
125
- }
126
- catch (error) {
127
- console.error("Error retrieving website configuration", error);
128
- }
129
- if (!this.websiteConfiguration) {
130
- throw new Error("Website configuration cannot be retrieved");
131
- }
132
- }
133
262
  /*
134
263
  * Initialize the client-side tracker.
135
264
  * This method is used to initialize the Matomo tracker on the client-side, appending a script tag to the head of the document.
@@ -139,260 +268,196 @@ export class Analytics extends BaseClient {
139
268
  * await analytics.initClientTracker({ user_id: "123" });
140
269
  */
141
270
  async initClientTracker(overrideConfig) {
271
+ if (!isBrowser()) {
272
+ throw new Error("initClientTracker can only be called on the client-side");
273
+ }
142
274
  await this.ensureWebsiteConfiguration();
143
275
  initTracker({
144
276
  websiteConfiguration: this.websiteConfiguration,
145
277
  overrideConfig,
146
278
  });
147
279
  }
148
- async trackPush(eventName, eventArguments, siteIds) {
149
- await this.ensureWebsiteConfiguration();
150
- if (this.isDryRun) {
151
- console.warn("Dry run is enabled, skipping request");
152
- return;
153
- }
154
- if (this.isOptOut) {
155
- console.warn("Opt out is enabled, skipping request");
156
- return;
157
- }
158
- if (!siteIds?.length)
159
- return push([eventName, ...eventArguments]);
160
- const trackerEndpoint = `${this.websiteConfiguration.tracker_url}/${this.websiteConfiguration.bypass_adblockers ? "tr4ck3rp" : "matomo.php"}`;
161
- try {
162
- for (const siteId of siteIds.map(String)) {
163
- const matomoTracker = getTracker(trackerEndpoint, siteId);
164
- matomoTracker[eventName](...eventArguments);
165
- }
166
- return { data: "success" };
167
- }
168
- catch (error) {
169
- console.error("Error tracking event", error);
170
- return { error };
171
- }
172
- }
173
- async trackBackendAction(params) {
174
- if (!this.trackingWebsiteId) {
175
- throw new Error("Tracking website ID is not set");
176
- }
177
- const { url, data, generateCode } = params;
178
- return this.clientRequest(this.client.POST(url, {
179
- params: {
180
- path: {
181
- id: this.trackingWebsiteId,
280
+ administration = {
281
+ getWebsites: async () => {
282
+ this.checkBaseUrlAndToken();
283
+ return this.clientRequest(this.client.GET("/api/v1/websites/"));
284
+ },
285
+ getWebsiteById: async (id, query) => {
286
+ return this.clientRequest(this.client.GET("/api/v1/websites/{id}", {
287
+ params: {
288
+ path: {
289
+ id,
290
+ },
291
+ query,
182
292
  },
183
- query: {
184
- code: generateCode,
293
+ }));
294
+ },
295
+ createWebsite: async (data) => {
296
+ this.checkBaseUrlAndToken();
297
+ return this.clientRequest(this.client.POST("/api/v1/websites/", {
298
+ body: data,
299
+ }));
300
+ },
301
+ updateWebsite: async (id, data) => {
302
+ this.checkBaseUrlAndToken();
303
+ return this.clientRequest(this.client.PATCH("/api/v1/websites/{id}", {
304
+ params: {
305
+ path: {
306
+ id,
307
+ },
185
308
  },
186
- },
187
- body: {
188
- ...data,
189
- ...this.trackingMetadata,
190
- },
191
- }));
192
- }
193
- async getWebsites() {
194
- return this.clientRequest(this.client.GET("/api/v1/websites/"));
195
- }
196
- async getWebsiteById(id, query) {
197
- return this.clientRequest(this.client.GET("/api/v1/websites/{id}", {
198
- params: {
199
- path: {
200
- id,
201
- },
202
- query,
203
- },
204
- }));
205
- }
206
- async createWebsite(data) {
207
- return this.clientRequest(this.client.POST("/api/v1/websites/", {
208
- body: data,
209
- }));
210
- }
211
- async updateWebsite(id, data) {
212
- return this.clientRequest(this.client.PATCH("/api/v1/websites/{id}", {
213
- params: {
214
- path: {
215
- id,
216
- },
217
- },
218
- body: data,
219
- }));
220
- }
221
- async generateTrackingCode(query) {
222
- if (!this.trackingWebsiteId)
223
- throw new Error("Tracking website ID is not set");
224
- return this.clientRequest(this.client.GET("/api/v1/websites/{id}/tracking-code", {
225
- params: {
226
- path: {
227
- id: this.trackingWebsiteId,
309
+ body: data,
310
+ }));
311
+ },
312
+ };
313
+ generate = {
314
+ initTrackingJsCode: async (query) => {
315
+ this.checkBaseUrlAndToken();
316
+ if (!this.trackingWebsiteId)
317
+ throw new Error("Tracking website ID is not set");
318
+ return this.clientRequest(this.client.GET("/api/v1/websites/{id}/tracking-code", {
319
+ params: {
320
+ path: {
321
+ id: this.trackingWebsiteId,
322
+ },
323
+ query,
228
324
  },
229
- query,
230
- },
231
- }));
232
- }
233
- async trackEvent(data) {
234
- if (!isBrowser()) {
325
+ }));
326
+ },
327
+ trackEventJsCode: async (data) => {
235
328
  return this.trackBackendAction({
236
329
  url: "/api/v1/websites/{id}/track-event",
237
330
  data,
238
- generateCode: false,
331
+ generateCode: true,
239
332
  });
240
- }
241
- const { event, site_ids } = data;
242
- const eventArguments = [
243
- event.category,
244
- event.action,
245
- ...(event.name ? [event.name] : []),
246
- ...(event.value ? [event.value] : []),
247
- ];
248
- return this.trackPush("trackEvent", eventArguments, site_ids);
249
- }
250
- async generateTrackEventCode(data) {
251
- return this.trackBackendAction({
252
- url: "/api/v1/websites/{id}/track-event",
253
- data,
254
- generateCode: true,
255
- });
256
- }
257
- async trackPageView(data) {
258
- if (!isBrowser()) {
333
+ },
334
+ trackPageViewJsCode: async (data) => {
259
335
  return this.trackBackendAction({
260
336
  url: "/api/v1/websites/{id}/track-page-view",
261
337
  data,
262
- generateCode: false,
338
+ generateCode: true,
263
339
  });
264
- }
265
- const { event, site_ids } = data;
266
- const eventArguments = [event.action_name];
267
- return this.trackPush("trackPageView", eventArguments, site_ids);
268
- }
269
- async generateTrackPageViewCode(data) {
270
- return this.trackBackendAction({
271
- url: "/api/v1/websites/{id}/track-page-view",
272
- data,
273
- generateCode: true,
274
- });
275
- }
276
- async trackSiteSearch(data) {
277
- if (!isBrowser()) {
340
+ },
341
+ trackSiteSearchJsCode: async (data) => {
278
342
  return this.trackBackendAction({
279
343
  url: "/api/v1/websites/{id}/track-search",
280
344
  data,
281
- generateCode: false,
345
+ generateCode: true,
282
346
  });
283
- }
284
- const { event, site_ids } = data;
285
- const eventArguments = [
286
- event.search_keyword,
287
- ...(event.search_category ? [event.search_category] : []),
288
- ...(event.search_count ? [event.search_count] : []),
289
- ];
290
- return this.trackPush("trackSiteSearch", eventArguments, site_ids);
291
- }
292
- async generateTrackSiteSearchCode(data) {
293
- return this.trackBackendAction({
294
- url: "/api/v1/websites/{id}/track-search",
295
- data,
296
- generateCode: true,
297
- });
298
- }
299
- async trackLink(data) {
300
- if (!isBrowser()) {
347
+ },
348
+ trackLinkJsCode: async (data) => {
301
349
  return this.trackBackendAction({
302
350
  url: "/api/v1/websites/{id}/track-link",
303
351
  data,
304
- generateCode: false,
352
+ generateCode: true,
305
353
  });
306
- }
307
- const { event, site_ids } = data;
308
- const eventArguments = [event.link, event.linkType];
309
- return this.trackPush("trackLink", eventArguments, site_ids);
310
- }
311
- async generateTrackLinkCode(data) {
312
- return this.trackBackendAction({
313
- url: "/api/v1/websites/{id}/track-link",
314
- data,
315
- generateCode: true,
316
- });
317
- }
318
- async trackContentImpression(data) {
319
- if (!isBrowser()) {
354
+ },
355
+ trackContentImpressionJsCode: async (data) => {
320
356
  return this.trackBackendAction({
321
357
  url: "/api/v1/websites/{id}/track-content-impression",
322
358
  data,
323
- generateCode: false,
359
+ generateCode: true,
324
360
  });
325
- }
326
- const { event, site_ids } = data;
327
- const eventArguments = [
328
- event.content_name,
329
- event.content_piece,
330
- event.content_target,
331
- ];
332
- return this.trackPush("trackContentImpression", eventArguments, site_ids);
333
- }
334
- async generateTrackContentImpressionCode(data) {
335
- return this.trackBackendAction({
336
- url: "/api/v1/websites/{id}/track-content-impression",
337
- data,
338
- generateCode: true,
339
- });
340
- }
341
- async trackContentInteraction(data) {
342
- if (!isBrowser()) {
361
+ },
362
+ trackContentInteractionJsCode: async (data) => {
343
363
  return this.trackBackendAction({
344
364
  url: "/api/v1/websites/{id}/track-content-interaction",
345
365
  data,
346
- generateCode: false,
366
+ generateCode: true,
347
367
  });
348
- }
349
- const { event, site_ids } = data;
350
- const eventArguments = [
351
- event.content_interaction,
352
- event.content_name,
353
- event.content_piece,
354
- event.content_target,
355
- ];
356
- return this.trackPush("trackContentInteraction", eventArguments, site_ids);
357
- }
358
- async generateTrackContentInteractionCode(data) {
359
- return this.trackBackendAction({
360
- url: "/api/v1/websites/{id}/track-content-interaction",
361
- data,
362
- generateCode: true,
363
- });
364
- }
368
+ },
369
+ };
370
+ track = {
371
+ event: async (data) => {
372
+ if (!isBrowser()) {
373
+ return this.trackBackendAction({
374
+ url: "/api/v1/websites/{id}/track-event",
375
+ data,
376
+ generateCode: false,
377
+ });
378
+ }
379
+ const { event, site_ids, contextOverride } = data;
380
+ const eventArguments = [
381
+ event.category,
382
+ event.action,
383
+ ...(event.name ? [event.name] : []),
384
+ ...(event.value ? [event.value] : []),
385
+ ];
386
+ return this.trackPush("trackEvent", eventArguments, site_ids, contextOverride);
387
+ },
388
+ pageView: async (data) => {
389
+ if (!isBrowser()) {
390
+ return this.trackBackendAction({
391
+ url: "/api/v1/websites/{id}/track-page-view",
392
+ data,
393
+ generateCode: false,
394
+ });
395
+ }
396
+ const { event, site_ids, contextOverride } = data;
397
+ const eventArguments = [event.action_name];
398
+ return this.trackPush("trackPageView", eventArguments, site_ids, contextOverride);
399
+ },
400
+ siteSearch: async (data) => {
401
+ if (!isBrowser()) {
402
+ return this.trackBackendAction({
403
+ url: "/api/v1/websites/{id}/track-search",
404
+ data,
405
+ generateCode: false,
406
+ });
407
+ }
408
+ const { event, site_ids, contextOverride } = data;
409
+ const eventArguments = [
410
+ event.search_keyword,
411
+ ...(event.search_category ? [event.search_category] : []),
412
+ ...(event.search_count ? [event.search_count] : []),
413
+ ];
414
+ return this.trackPush("trackSiteSearch", eventArguments, site_ids, contextOverride);
415
+ },
416
+ link: async (data) => {
417
+ if (!isBrowser()) {
418
+ return this.trackBackendAction({
419
+ url: "/api/v1/websites/{id}/track-link",
420
+ data,
421
+ generateCode: false,
422
+ });
423
+ }
424
+ const { event, site_ids, contextOverride } = data;
425
+ const eventArguments = [event.link, event.linkType];
426
+ return this.trackPush("trackLink", eventArguments, site_ids, contextOverride);
427
+ },
428
+ contentImpression: async (data) => {
429
+ if (!isBrowser()) {
430
+ return this.trackBackendAction({
431
+ url: "/api/v1/websites/{id}/track-content-impression",
432
+ data,
433
+ generateCode: false,
434
+ });
435
+ }
436
+ const { event, site_ids, contextOverride } = data;
437
+ const eventArguments = [
438
+ event.content_name,
439
+ event.content_piece,
440
+ event.content_target,
441
+ ];
442
+ return this.trackPush("trackContentImpression", eventArguments, site_ids, contextOverride);
443
+ },
444
+ contentInteraction: async (data) => {
445
+ if (!isBrowser()) {
446
+ return this.trackBackendAction({
447
+ url: "/api/v1/websites/{id}/track-content-interaction",
448
+ data,
449
+ generateCode: false,
450
+ });
451
+ }
452
+ const { event, site_ids, contextOverride } = data;
453
+ const eventArguments = [
454
+ event.content_interaction,
455
+ event.content_name,
456
+ event.content_piece,
457
+ event.content_target,
458
+ ];
459
+ return this.trackPush("trackContentInteraction", eventArguments, site_ids, contextOverride);
460
+ },
461
+ };
365
462
  }
366
- __decorate([
367
- needsBackend
368
- ], Analytics.prototype, "trackBackendAction", null);
369
- __decorate([
370
- needsBackend
371
- ], Analytics.prototype, "getWebsites", null);
372
- __decorate([
373
- needsBackend
374
- ], Analytics.prototype, "createWebsite", null);
375
- __decorate([
376
- needsBackend
377
- ], Analytics.prototype, "updateWebsite", null);
378
- __decorate([
379
- needsBackend
380
- ], Analytics.prototype, "generateTrackingCode", null);
381
- __decorate([
382
- needsBackend
383
- ], Analytics.prototype, "generateTrackEventCode", null);
384
- __decorate([
385
- needsBackend
386
- ], Analytics.prototype, "generateTrackPageViewCode", null);
387
- __decorate([
388
- needsBackend
389
- ], Analytics.prototype, "generateTrackSiteSearchCode", null);
390
- __decorate([
391
- needsBackend
392
- ], Analytics.prototype, "generateTrackLinkCode", null);
393
- __decorate([
394
- needsBackend
395
- ], Analytics.prototype, "generateTrackContentImpressionCode", null);
396
- __decorate([
397
- needsBackend
398
- ], Analytics.prototype, "generateTrackContentInteractionCode", null);
463
+ //# sourceMappingURL=index.js.map