opscms-analytics-plugin 1.0.0 → 1.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.
- package/CHANGELOG.md +4 -0
- package/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +38 -2
- package/dist/index.mjs +34 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
A site admin's tracking ID, Tag Manager ID and server address are checked when saved: each must have the shape a real one has, so nothing that could end a string or a tag in the inline snippet is accepted (the server address must be https, with no login in it). Empty stays allowed.
|
|
6
|
+
|
|
3
7
|
## 1.0.0
|
|
4
8
|
|
|
5
9
|
First release as a package of its own (it was part of the platform's code). Keeps a site's analytics providers in its own table,
|
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,18 @@ declare const AnalyticsIntegrations: CollectionConfig;
|
|
|
33
33
|
|
|
34
34
|
declare const analyticsManifest: opscms_sdk.PluginManifest;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* What an analytics integration's own values may look like.
|
|
38
|
+
*
|
|
39
|
+
* A site's admin types these (the customer's own script is a separate field only the platform owner can write), and they end up inside
|
|
40
|
+
* every page of the site: as part of a script address and inside an inline snippet. So each is held to the shape a real one has, and
|
|
41
|
+
* nothing that could end a string or a tag is accepted. (The component that renders them escapes them as well; this is the first line.)
|
|
42
|
+
*/
|
|
43
|
+
/** `true`, or the sentence that tells the person what is wrong. Empty is allowed: the field is optional. */
|
|
44
|
+
declare function trackingIdProblem(value: unknown): true | string;
|
|
45
|
+
declare function tagIdProblem(value: unknown): true | string;
|
|
46
|
+
declare function serverUrlProblem(value: unknown): true | string;
|
|
47
|
+
|
|
36
48
|
/** Resolve a field_mapping of { paramName: "{{template}}" } against the workflow context. */
|
|
37
49
|
declare function resolveParams(mapping: Record<string, unknown> | null | undefined, ctx: Record<string, unknown>): Record<string, string>;
|
|
38
50
|
/** Build the GA4 Measurement Protocol request body. Exposed for unit verification. */
|
|
@@ -57,4 +69,4 @@ declare function ga4SendHandler(ctx: WorkflowActionContext): Promise<WorkflowSte
|
|
|
57
69
|
*/
|
|
58
70
|
declare const analyticsPlugin: opscms_sdk.PlatformPlugin;
|
|
59
71
|
|
|
60
|
-
export { ANALYTICS_INTEGRATIONS, AnalyticsIntegrations, analyticsManifest, analyticsPlugin, buildGa4Body, ga4SendHandler, resolveParams };
|
|
72
|
+
export { ANALYTICS_INTEGRATIONS, AnalyticsIntegrations, analyticsManifest, analyticsPlugin, buildGa4Body, ga4SendHandler, resolveParams, serverUrlProblem, tagIdProblem, trackingIdProblem };
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,18 @@ declare const AnalyticsIntegrations: CollectionConfig;
|
|
|
33
33
|
|
|
34
34
|
declare const analyticsManifest: opscms_sdk.PluginManifest;
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* What an analytics integration's own values may look like.
|
|
38
|
+
*
|
|
39
|
+
* A site's admin types these (the customer's own script is a separate field only the platform owner can write), and they end up inside
|
|
40
|
+
* every page of the site: as part of a script address and inside an inline snippet. So each is held to the shape a real one has, and
|
|
41
|
+
* nothing that could end a string or a tag is accepted. (The component that renders them escapes them as well; this is the first line.)
|
|
42
|
+
*/
|
|
43
|
+
/** `true`, or the sentence that tells the person what is wrong. Empty is allowed: the field is optional. */
|
|
44
|
+
declare function trackingIdProblem(value: unknown): true | string;
|
|
45
|
+
declare function tagIdProblem(value: unknown): true | string;
|
|
46
|
+
declare function serverUrlProblem(value: unknown): true | string;
|
|
47
|
+
|
|
36
48
|
/** Resolve a field_mapping of { paramName: "{{template}}" } against the workflow context. */
|
|
37
49
|
declare function resolveParams(mapping: Record<string, unknown> | null | undefined, ctx: Record<string, unknown>): Record<string, string>;
|
|
38
50
|
/** Build the GA4 Measurement Protocol request body. Exposed for unit verification. */
|
|
@@ -57,4 +69,4 @@ declare function ga4SendHandler(ctx: WorkflowActionContext): Promise<WorkflowSte
|
|
|
57
69
|
*/
|
|
58
70
|
declare const analyticsPlugin: opscms_sdk.PlatformPlugin;
|
|
59
71
|
|
|
60
|
-
export { ANALYTICS_INTEGRATIONS, AnalyticsIntegrations, analyticsManifest, analyticsPlugin, buildGa4Body, ga4SendHandler, resolveParams };
|
|
72
|
+
export { ANALYTICS_INTEGRATIONS, AnalyticsIntegrations, analyticsManifest, analyticsPlugin, buildGa4Body, ga4SendHandler, resolveParams, serverUrlProblem, tagIdProblem, trackingIdProblem };
|
package/dist/index.js
CHANGED
|
@@ -26,13 +26,43 @@ __export(index_exports, {
|
|
|
26
26
|
analyticsPlugin: () => analyticsPlugin,
|
|
27
27
|
buildGa4Body: () => buildGa4Body,
|
|
28
28
|
ga4SendHandler: () => ga4SendHandler,
|
|
29
|
-
resolveParams: () => resolveParams
|
|
29
|
+
resolveParams: () => resolveParams,
|
|
30
|
+
serverUrlProblem: () => serverUrlProblem,
|
|
31
|
+
tagIdProblem: () => tagIdProblem,
|
|
32
|
+
trackingIdProblem: () => trackingIdProblem
|
|
30
33
|
});
|
|
31
34
|
module.exports = __toCommonJS(index_exports);
|
|
32
35
|
var import_opscms_sdk5 = require("opscms-sdk");
|
|
33
36
|
|
|
34
37
|
// src/AnalyticsIntegrations.ts
|
|
35
38
|
var import_opscms_sdk = require("opscms-sdk");
|
|
39
|
+
|
|
40
|
+
// src/integrationValues.ts
|
|
41
|
+
var ID = /^[A-Za-z0-9._:/-]{1,100}$/;
|
|
42
|
+
var TAG = /^[A-Za-z0-9_-]{1,40}$/;
|
|
43
|
+
function trackingIdProblem(value) {
|
|
44
|
+
if (value === void 0 || value === null || value === "") return true;
|
|
45
|
+
return typeof value === "string" && ID.test(value) ? true : "A tracking or site ID has only letters, digits and . _ : / - (for example G-ABC123, 3, or example.com).";
|
|
46
|
+
}
|
|
47
|
+
function tagIdProblem(value) {
|
|
48
|
+
if (value === void 0 || value === null || value === "") return true;
|
|
49
|
+
return typeof value === "string" && TAG.test(value) ? true : "A Tag Manager container ID looks like GTM-ABC123.";
|
|
50
|
+
}
|
|
51
|
+
function serverUrlProblem(value) {
|
|
52
|
+
if (value === void 0 || value === null || value === "") return true;
|
|
53
|
+
if (typeof value !== "string" || value.length > 300 || /[\s"'<>`\\]/.test(value)) return "That is not a web address.";
|
|
54
|
+
let url;
|
|
55
|
+
try {
|
|
56
|
+
url = new URL(value);
|
|
57
|
+
} catch {
|
|
58
|
+
return "That is not a web address (it should look like https://analytics.example.com/).";
|
|
59
|
+
}
|
|
60
|
+
if (url.protocol !== "https:") return "The address must start with https:// (a page served over https cannot load a script from plain http).";
|
|
61
|
+
if (url.username || url.password) return "The address cannot contain a username or password.";
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/AnalyticsIntegrations.ts
|
|
36
66
|
var ANALYTICS_INTEGRATIONS = "analytics-integrations";
|
|
37
67
|
var onlySuperAdminField = ({ req }) => req?.user?.role === "super-admin";
|
|
38
68
|
var AnalyticsIntegrations = {
|
|
@@ -73,6 +103,7 @@ var AnalyticsIntegrations = {
|
|
|
73
103
|
{
|
|
74
104
|
name: "trackingId",
|
|
75
105
|
type: "text",
|
|
106
|
+
validate: (value) => trackingIdProblem(value),
|
|
76
107
|
admin: {
|
|
77
108
|
description: "Measurement / tracking ID \u2014 GA4 measurement ID (G-XXXX) for Google, or site ID for others. Leave blank if only using Tag Manager.",
|
|
78
109
|
condition: (_data, siblingData) => ["google", "matomo", "plausible", "fathom", "umami", "posthog"].includes(
|
|
@@ -83,6 +114,7 @@ var AnalyticsIntegrations = {
|
|
|
83
114
|
{
|
|
84
115
|
name: "tagId",
|
|
85
116
|
type: "text",
|
|
117
|
+
validate: (value) => tagIdProblem(value),
|
|
86
118
|
admin: {
|
|
87
119
|
description: "Google Tag Manager container ID (GTM-XXXX). Leave blank if not using Tag Manager.",
|
|
88
120
|
condition: (_data, siblingData) => siblingData?.provider === "google"
|
|
@@ -99,6 +131,7 @@ var AnalyticsIntegrations = {
|
|
|
99
131
|
{
|
|
100
132
|
name: "serverUrl",
|
|
101
133
|
type: "text",
|
|
134
|
+
validate: (value) => serverUrlProblem(value),
|
|
102
135
|
admin: {
|
|
103
136
|
description: "Self-hosted instance URL (Matomo, Umami, Plausible, PostHog)",
|
|
104
137
|
condition: (_data, siblingData) => ["matomo", "plausible", "umami", "posthog"].includes(siblingData?.provider)
|
|
@@ -297,5 +330,8 @@ var analyticsPlugin = (0, import_opscms_sdk5.definePlugin)({
|
|
|
297
330
|
analyticsPlugin,
|
|
298
331
|
buildGa4Body,
|
|
299
332
|
ga4SendHandler,
|
|
300
|
-
resolveParams
|
|
333
|
+
resolveParams,
|
|
334
|
+
serverUrlProblem,
|
|
335
|
+
tagIdProblem,
|
|
336
|
+
trackingIdProblem
|
|
301
337
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,33 @@ import { definePlugin } from "opscms-sdk";
|
|
|
3
3
|
|
|
4
4
|
// src/AnalyticsIntegrations.ts
|
|
5
5
|
import { access, secretField, tenancy } from "opscms-sdk";
|
|
6
|
+
|
|
7
|
+
// src/integrationValues.ts
|
|
8
|
+
var ID = /^[A-Za-z0-9._:/-]{1,100}$/;
|
|
9
|
+
var TAG = /^[A-Za-z0-9_-]{1,40}$/;
|
|
10
|
+
function trackingIdProblem(value) {
|
|
11
|
+
if (value === void 0 || value === null || value === "") return true;
|
|
12
|
+
return typeof value === "string" && ID.test(value) ? true : "A tracking or site ID has only letters, digits and . _ : / - (for example G-ABC123, 3, or example.com).";
|
|
13
|
+
}
|
|
14
|
+
function tagIdProblem(value) {
|
|
15
|
+
if (value === void 0 || value === null || value === "") return true;
|
|
16
|
+
return typeof value === "string" && TAG.test(value) ? true : "A Tag Manager container ID looks like GTM-ABC123.";
|
|
17
|
+
}
|
|
18
|
+
function serverUrlProblem(value) {
|
|
19
|
+
if (value === void 0 || value === null || value === "") return true;
|
|
20
|
+
if (typeof value !== "string" || value.length > 300 || /[\s"'<>`\\]/.test(value)) return "That is not a web address.";
|
|
21
|
+
let url;
|
|
22
|
+
try {
|
|
23
|
+
url = new URL(value);
|
|
24
|
+
} catch {
|
|
25
|
+
return "That is not a web address (it should look like https://analytics.example.com/).";
|
|
26
|
+
}
|
|
27
|
+
if (url.protocol !== "https:") return "The address must start with https:// (a page served over https cannot load a script from plain http).";
|
|
28
|
+
if (url.username || url.password) return "The address cannot contain a username or password.";
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/AnalyticsIntegrations.ts
|
|
6
33
|
var ANALYTICS_INTEGRATIONS = "analytics-integrations";
|
|
7
34
|
var onlySuperAdminField = ({ req }) => req?.user?.role === "super-admin";
|
|
8
35
|
var AnalyticsIntegrations = {
|
|
@@ -43,6 +70,7 @@ var AnalyticsIntegrations = {
|
|
|
43
70
|
{
|
|
44
71
|
name: "trackingId",
|
|
45
72
|
type: "text",
|
|
73
|
+
validate: (value) => trackingIdProblem(value),
|
|
46
74
|
admin: {
|
|
47
75
|
description: "Measurement / tracking ID \u2014 GA4 measurement ID (G-XXXX) for Google, or site ID for others. Leave blank if only using Tag Manager.",
|
|
48
76
|
condition: (_data, siblingData) => ["google", "matomo", "plausible", "fathom", "umami", "posthog"].includes(
|
|
@@ -53,6 +81,7 @@ var AnalyticsIntegrations = {
|
|
|
53
81
|
{
|
|
54
82
|
name: "tagId",
|
|
55
83
|
type: "text",
|
|
84
|
+
validate: (value) => tagIdProblem(value),
|
|
56
85
|
admin: {
|
|
57
86
|
description: "Google Tag Manager container ID (GTM-XXXX). Leave blank if not using Tag Manager.",
|
|
58
87
|
condition: (_data, siblingData) => siblingData?.provider === "google"
|
|
@@ -69,6 +98,7 @@ var AnalyticsIntegrations = {
|
|
|
69
98
|
{
|
|
70
99
|
name: "serverUrl",
|
|
71
100
|
type: "text",
|
|
101
|
+
validate: (value) => serverUrlProblem(value),
|
|
72
102
|
admin: {
|
|
73
103
|
description: "Self-hosted instance URL (Matomo, Umami, Plausible, PostHog)",
|
|
74
104
|
condition: (_data, siblingData) => ["matomo", "plausible", "umami", "posthog"].includes(siblingData?.provider)
|
|
@@ -266,5 +296,8 @@ export {
|
|
|
266
296
|
analyticsPlugin,
|
|
267
297
|
buildGa4Body,
|
|
268
298
|
ga4SendHandler,
|
|
269
|
-
resolveParams
|
|
299
|
+
resolveParams,
|
|
300
|
+
serverUrlProblem,
|
|
301
|
+
tagIdProblem,
|
|
302
|
+
trackingIdProblem
|
|
270
303
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opscms-analytics-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Per-site analytics for an OpsCMS platform: each site's own Google, Matomo, Plausible, Fathom, Umami, PostHog or custom settings, and the server-side GA4 workflow action.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|