@ogcio/analytics-sdk 0.0.1-beta.2 → 0.0.1-beta.3
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/base/base-client.d.ts +2 -7
- package/dist/base/base-client.d.ts.map +1 -1
- package/dist/base/base-client.js +3 -15
- package/dist/base/base-client.js.map +1 -0
- package/{types.d.ts → dist/browser-types.d.ts} +1 -1
- package/dist/index.d.ts +397 -1138
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +311 -254
- package/dist/index.js.map +1 -0
- package/dist/matomo/helpers.d.ts +8 -1
- package/dist/matomo/helpers.d.ts.map +1 -1
- package/dist/matomo/helpers.js +2 -1
- package/dist/matomo/helpers.js.map +1 -0
- package/dist/matomo/types.d.ts +2 -1
- package/dist/matomo/types.d.ts.map +1 -1
- package/dist/matomo/types.js +1 -0
- package/dist/matomo/types.js.map +1 -0
- package/dist/schema.d.ts +84 -444
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -0
- package/dist/schema.js.map +1 -0
- package/dist/support-files/auth/index.js +1 -0
- package/dist/support-files/auth/index.js.map +1 -0
- package/dist/support-files/auth/types.d.ts +1 -1
- package/dist/support-files/auth/types.d.ts.map +1 -1
- package/dist/support-files/auth/types.js +1 -0
- package/dist/support-files/auth/types.js.map +1 -0
- package/dist/support-files/building-blocks-sdk.d.ts +1 -1
- package/dist/support-files/building-blocks-sdk.d.ts.map +1 -1
- package/dist/support-files/building-blocks-sdk.js +1 -0
- package/dist/support-files/building-blocks-sdk.js.map +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +19 -11
- package/examples/environment.d.ts +0 -11
- package/examples/index.ts +0 -201
- package/examples/tsconfig.json +0 -15
- package/src/base/base-client.ts +0 -172
- package/src/index.test.ts +0 -92
- package/src/index.ts +0 -543
- package/src/matomo/helpers.ts +0 -115
- package/src/matomo/types.ts +0 -64
- package/src/schema.ts +0 -1491
- package/src/support-files/auth/index.ts +0 -116
- package/src/support-files/auth/types.ts +0 -38
- package/src/support-files/building-blocks-sdk.ts +0 -32
- package/src/utils/index.test.ts +0 -46
- package/src/utils/index.ts +0 -20
- package/test-report.xml +0 -181
- 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,
|
|
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
|
-
|
|
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
|
|
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,29 @@ export class Analytics extends BaseClient {
|
|
|
93
202
|
getTrackingMetadata() {
|
|
94
203
|
return this.trackingMetadata;
|
|
95
204
|
}
|
|
205
|
+
setTrackingContext(context) {
|
|
206
|
+
this.trackingContext = { ...context };
|
|
207
|
+
if (this.trackingContext.customDimensions) {
|
|
208
|
+
for (const [dimensionId, value] of Object.entries(this.trackingContext.customDimensions)) {
|
|
209
|
+
push(["setCustomDimension", dimensionId, value]);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
clearTrackingContext() {
|
|
214
|
+
push(["resetUserId"]);
|
|
215
|
+
if (this.trackingContext?.customDimensions) {
|
|
216
|
+
for (const dimensionId of Object.keys(this.trackingContext.customDimensions)) {
|
|
217
|
+
push([
|
|
218
|
+
"deleteCustomDimension",
|
|
219
|
+
dimensionId.replace(DIMENSION_PREFIX, ""),
|
|
220
|
+
]);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
this.trackingContext = undefined;
|
|
224
|
+
}
|
|
225
|
+
getTrackingContext() {
|
|
226
|
+
return this.trackingContext;
|
|
227
|
+
}
|
|
96
228
|
/*
|
|
97
229
|
* The dryRun flag, when set, prevents any data from being sent to the API.
|
|
98
230
|
* This is useful for testing/debugging purposes.
|
|
@@ -119,17 +251,6 @@ export class Analytics extends BaseClient {
|
|
|
119
251
|
this.isDryRun = config.dryRun;
|
|
120
252
|
this.isOptOut = config.optOut;
|
|
121
253
|
}
|
|
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
254
|
/*
|
|
134
255
|
* Initialize the client-side tracker.
|
|
135
256
|
* 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 +260,196 @@ export class Analytics extends BaseClient {
|
|
|
139
260
|
* await analytics.initClientTracker({ user_id: "123" });
|
|
140
261
|
*/
|
|
141
262
|
async initClientTracker(overrideConfig) {
|
|
263
|
+
if (!isBrowser()) {
|
|
264
|
+
throw new Error("initClientTracker can only be called on the client-side");
|
|
265
|
+
}
|
|
142
266
|
await this.ensureWebsiteConfiguration();
|
|
143
267
|
initTracker({
|
|
144
268
|
websiteConfiguration: this.websiteConfiguration,
|
|
145
269
|
overrideConfig,
|
|
146
270
|
});
|
|
147
271
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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,
|
|
272
|
+
administration = {
|
|
273
|
+
getWebsites: async () => {
|
|
274
|
+
this.checkBaseUrlAndToken();
|
|
275
|
+
return this.clientRequest(this.client.GET("/api/v1/websites/"));
|
|
276
|
+
},
|
|
277
|
+
getWebsiteById: async (id, query) => {
|
|
278
|
+
return this.clientRequest(this.client.GET("/api/v1/websites/{id}", {
|
|
279
|
+
params: {
|
|
280
|
+
path: {
|
|
281
|
+
id,
|
|
282
|
+
},
|
|
283
|
+
query,
|
|
182
284
|
},
|
|
183
|
-
|
|
184
|
-
|
|
285
|
+
}));
|
|
286
|
+
},
|
|
287
|
+
createWebsite: async (data) => {
|
|
288
|
+
this.checkBaseUrlAndToken();
|
|
289
|
+
return this.clientRequest(this.client.POST("/api/v1/websites/", {
|
|
290
|
+
body: data,
|
|
291
|
+
}));
|
|
292
|
+
},
|
|
293
|
+
updateWebsite: async (id, data) => {
|
|
294
|
+
this.checkBaseUrlAndToken();
|
|
295
|
+
return this.clientRequest(this.client.PATCH("/api/v1/websites/{id}", {
|
|
296
|
+
params: {
|
|
297
|
+
path: {
|
|
298
|
+
id,
|
|
299
|
+
},
|
|
185
300
|
},
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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,
|
|
301
|
+
body: data,
|
|
302
|
+
}));
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
generate = {
|
|
306
|
+
initTrackingJsCode: async (query) => {
|
|
307
|
+
this.checkBaseUrlAndToken();
|
|
308
|
+
if (!this.trackingWebsiteId)
|
|
309
|
+
throw new Error("Tracking website ID is not set");
|
|
310
|
+
return this.clientRequest(this.client.GET("/api/v1/websites/{id}/tracking-code", {
|
|
311
|
+
params: {
|
|
312
|
+
path: {
|
|
313
|
+
id: this.trackingWebsiteId,
|
|
314
|
+
},
|
|
315
|
+
query,
|
|
228
316
|
},
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
async trackEvent(data) {
|
|
234
|
-
if (!isBrowser()) {
|
|
317
|
+
}));
|
|
318
|
+
},
|
|
319
|
+
trackEventJsCode: async (data) => {
|
|
235
320
|
return this.trackBackendAction({
|
|
236
321
|
url: "/api/v1/websites/{id}/track-event",
|
|
237
322
|
data,
|
|
238
|
-
generateCode:
|
|
323
|
+
generateCode: true,
|
|
239
324
|
});
|
|
240
|
-
}
|
|
241
|
-
|
|
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()) {
|
|
325
|
+
},
|
|
326
|
+
trackPageViewJsCode: async (data) => {
|
|
259
327
|
return this.trackBackendAction({
|
|
260
328
|
url: "/api/v1/websites/{id}/track-page-view",
|
|
261
329
|
data,
|
|
262
|
-
generateCode:
|
|
330
|
+
generateCode: true,
|
|
263
331
|
});
|
|
264
|
-
}
|
|
265
|
-
|
|
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()) {
|
|
332
|
+
},
|
|
333
|
+
trackSiteSearchJsCode: async (data) => {
|
|
278
334
|
return this.trackBackendAction({
|
|
279
335
|
url: "/api/v1/websites/{id}/track-search",
|
|
280
336
|
data,
|
|
281
|
-
generateCode:
|
|
337
|
+
generateCode: true,
|
|
282
338
|
});
|
|
283
|
-
}
|
|
284
|
-
|
|
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()) {
|
|
339
|
+
},
|
|
340
|
+
trackLinkJsCode: async (data) => {
|
|
301
341
|
return this.trackBackendAction({
|
|
302
342
|
url: "/api/v1/websites/{id}/track-link",
|
|
303
343
|
data,
|
|
304
|
-
generateCode:
|
|
344
|
+
generateCode: true,
|
|
305
345
|
});
|
|
306
|
-
}
|
|
307
|
-
|
|
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()) {
|
|
346
|
+
},
|
|
347
|
+
trackContentImpressionJsCode: async (data) => {
|
|
320
348
|
return this.trackBackendAction({
|
|
321
349
|
url: "/api/v1/websites/{id}/track-content-impression",
|
|
322
350
|
data,
|
|
323
|
-
generateCode:
|
|
351
|
+
generateCode: true,
|
|
324
352
|
});
|
|
325
|
-
}
|
|
326
|
-
|
|
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()) {
|
|
353
|
+
},
|
|
354
|
+
trackContentInteractionJsCode: async (data) => {
|
|
343
355
|
return this.trackBackendAction({
|
|
344
356
|
url: "/api/v1/websites/{id}/track-content-interaction",
|
|
345
357
|
data,
|
|
346
|
-
generateCode:
|
|
358
|
+
generateCode: true,
|
|
347
359
|
});
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
track = {
|
|
363
|
+
event: async (data) => {
|
|
364
|
+
if (!isBrowser()) {
|
|
365
|
+
return this.trackBackendAction({
|
|
366
|
+
url: "/api/v1/websites/{id}/track-event",
|
|
367
|
+
data,
|
|
368
|
+
generateCode: false,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
const { event, site_ids, contextOverride } = data;
|
|
372
|
+
const eventArguments = [
|
|
373
|
+
event.category,
|
|
374
|
+
event.action,
|
|
375
|
+
...(event.name ? [event.name] : []),
|
|
376
|
+
...(event.value ? [event.value] : []),
|
|
377
|
+
];
|
|
378
|
+
return this.trackPush("trackEvent", eventArguments, site_ids, contextOverride);
|
|
379
|
+
},
|
|
380
|
+
pageView: async (data) => {
|
|
381
|
+
if (!isBrowser()) {
|
|
382
|
+
return this.trackBackendAction({
|
|
383
|
+
url: "/api/v1/websites/{id}/track-page-view",
|
|
384
|
+
data,
|
|
385
|
+
generateCode: false,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
const { event, site_ids, contextOverride } = data;
|
|
389
|
+
const eventArguments = [event.action_name];
|
|
390
|
+
return this.trackPush("trackPageView", eventArguments, site_ids, contextOverride);
|
|
391
|
+
},
|
|
392
|
+
siteSearch: async (data) => {
|
|
393
|
+
if (!isBrowser()) {
|
|
394
|
+
return this.trackBackendAction({
|
|
395
|
+
url: "/api/v1/websites/{id}/track-search",
|
|
396
|
+
data,
|
|
397
|
+
generateCode: false,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const { event, site_ids, contextOverride } = data;
|
|
401
|
+
const eventArguments = [
|
|
402
|
+
event.search_keyword,
|
|
403
|
+
...(event.search_category ? [event.search_category] : []),
|
|
404
|
+
...(event.search_count ? [event.search_count] : []),
|
|
405
|
+
];
|
|
406
|
+
return this.trackPush("trackSiteSearch", eventArguments, site_ids, contextOverride);
|
|
407
|
+
},
|
|
408
|
+
link: async (data) => {
|
|
409
|
+
if (!isBrowser()) {
|
|
410
|
+
return this.trackBackendAction({
|
|
411
|
+
url: "/api/v1/websites/{id}/track-link",
|
|
412
|
+
data,
|
|
413
|
+
generateCode: false,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
const { event, site_ids, contextOverride } = data;
|
|
417
|
+
const eventArguments = [event.link, event.linkType];
|
|
418
|
+
return this.trackPush("trackLink", eventArguments, site_ids, contextOverride);
|
|
419
|
+
},
|
|
420
|
+
contentImpression: async (data) => {
|
|
421
|
+
if (!isBrowser()) {
|
|
422
|
+
return this.trackBackendAction({
|
|
423
|
+
url: "/api/v1/websites/{id}/track-content-impression",
|
|
424
|
+
data,
|
|
425
|
+
generateCode: false,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
const { event, site_ids, contextOverride } = data;
|
|
429
|
+
const eventArguments = [
|
|
430
|
+
event.content_name,
|
|
431
|
+
event.content_piece,
|
|
432
|
+
event.content_target,
|
|
433
|
+
];
|
|
434
|
+
return this.trackPush("trackContentImpression", eventArguments, site_ids, contextOverride);
|
|
435
|
+
},
|
|
436
|
+
contentInteraction: async (data) => {
|
|
437
|
+
if (!isBrowser()) {
|
|
438
|
+
return this.trackBackendAction({
|
|
439
|
+
url: "/api/v1/websites/{id}/track-content-interaction",
|
|
440
|
+
data,
|
|
441
|
+
generateCode: false,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
const { event, site_ids, contextOverride } = data;
|
|
445
|
+
const eventArguments = [
|
|
446
|
+
event.content_interaction,
|
|
447
|
+
event.content_name,
|
|
448
|
+
event.content_piece,
|
|
449
|
+
event.content_target,
|
|
450
|
+
];
|
|
451
|
+
return this.trackPush("trackContentInteraction", eventArguments, site_ids, contextOverride);
|
|
452
|
+
},
|
|
453
|
+
};
|
|
365
454
|
}
|
|
366
|
-
|
|
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);
|
|
455
|
+
//# sourceMappingURL=index.js.map
|