@getuserfeedback/adapters 0.4.5 → 0.5.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/README.md +48 -43
- package/dist/gtm/core.d.ts +1 -29
- package/dist/gtm/core.d.ts.map +1 -1
- package/dist/gtm/core.js +17 -71
- package/dist/gtm/index.d.ts +2 -2
- package/dist/gtm/index.d.ts.map +1 -1
- package/dist/gtm/index.js +2 -2
- package/dist/gtm/runtime-model.d.ts +28 -0
- package/dist/gtm/runtime-model.d.ts.map +1 -0
- package/dist/gtm/runtime-model.js +216 -0
- package/dist/gtm/template-generation.d.ts +22 -0
- package/dist/gtm/template-generation.d.ts.map +1 -1
- package/dist/gtm/template-generation.js +245 -366
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -6,25 +6,20 @@
|
|
|
6
6
|
|
|
7
7
|
The `@getuserfeedback/adapters/gtm` entrypoint is the authoritative source for Google Tag Manager template generation. It owns:
|
|
8
8
|
|
|
9
|
-
- GTM
|
|
10
|
-
- GTM theme normalization logic
|
|
9
|
+
- GTM color scheme normalization logic
|
|
11
10
|
- GTM template parameter generation
|
|
12
11
|
- GTM runtime source generation
|
|
13
12
|
- GTM permission generation
|
|
13
|
+
- GTM importable `template.tpl` file generation
|
|
14
14
|
- GTM template defaults, help text, and option labels
|
|
15
15
|
- the canonical loader script base URL pattern
|
|
16
16
|
|
|
17
17
|
### Public exports
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Template inputs and init translation:
|
|
20
20
|
|
|
21
21
|
- `GTM_CONSENT_TYPES`
|
|
22
|
-
- `ESSENTIAL_GTM_SCOPES`
|
|
23
|
-
- `DEFAULT_GTM_SCOPE_MAPPINGS`
|
|
24
|
-
- `GTM_TEMPLATE_SCOPE_OPTIONS`
|
|
25
|
-
- `GTM_TEMPLATE_MAPPING_OPTIONS`
|
|
26
22
|
- `isGtmConsentType(value)`
|
|
27
|
-
- `isHostConfigurableGtmScope(scope)`
|
|
28
23
|
- `normalizeGtmThemeInput(input)`
|
|
29
24
|
- `resolveDefaultConsentFromGtm(input)`
|
|
30
25
|
- `buildInitOptionsFromGtmTemplate(input)`
|
|
@@ -34,11 +29,7 @@ Types:
|
|
|
34
29
|
- `GtmConsentType`
|
|
35
30
|
- `GtmConsentValue`
|
|
36
31
|
- `GtmConsentState`
|
|
37
|
-
- `GtmScopeMapping`
|
|
38
|
-
- `GtmAnalyticsMeasurementMode`
|
|
39
32
|
- `GtmTemplateInput`
|
|
40
|
-
- `GtmTemplateScopeOption`
|
|
41
|
-
- `GtmTemplateMappingOption`
|
|
42
33
|
|
|
43
34
|
Template generation:
|
|
44
35
|
|
|
@@ -49,29 +40,19 @@ Template generation:
|
|
|
49
40
|
- `buildGtmTemplateInfo(options?)`
|
|
50
41
|
- `buildGtmTemplateParts(options?)`
|
|
51
42
|
- `buildGtmTemplateArtifact(options?)`
|
|
43
|
+
- `buildGtmTemplateFileSource(options?)`
|
|
52
44
|
|
|
53
|
-
###
|
|
45
|
+
### Consent behavior
|
|
54
46
|
|
|
55
|
-
|
|
47
|
+
The GTM template no longer exposes consent settings in its UI.
|
|
56
48
|
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
- Generated help text states that they are fixed by the loader.
|
|
49
|
+
- Default consent is derived automatically from Google Consent Mode state.
|
|
50
|
+
- `analytics.measurement` follows `analytics.storage`.
|
|
51
|
+
- If no GTM consent state is available, the adapter leaves `defaultConsent` unset.
|
|
61
52
|
|
|
62
|
-
###
|
|
53
|
+
### Color scheme behavior
|
|
63
54
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
- `inherit-analytics-storage`
|
|
67
|
-
- `granted`
|
|
68
|
-
- `denied`
|
|
69
|
-
|
|
70
|
-
Manual GTM consent mode does not apply hidden analytics measurement behavior. It only uses the generated host-configurable scope mappings.
|
|
71
|
-
|
|
72
|
-
### Theme behavior
|
|
73
|
-
|
|
74
|
-
Generated GTM theme support accepts:
|
|
55
|
+
Generated GTM color scheme support accepts:
|
|
75
56
|
|
|
76
57
|
- fixed `light`
|
|
77
58
|
- fixed `dark`
|
|
@@ -80,35 +61,56 @@ Generated GTM theme support accepts:
|
|
|
80
61
|
- GTM variable-driven values
|
|
81
62
|
- comma-separated auto-detect attribute lists
|
|
82
63
|
|
|
83
|
-
The adapter normalizes all
|
|
64
|
+
The adapter normalizes all of these into protocol-valid `colorScheme`.
|
|
84
65
|
|
|
85
|
-
###
|
|
66
|
+
### Identity behavior
|
|
67
|
+
|
|
68
|
+
The generated template supports:
|
|
69
|
+
|
|
70
|
+
- `Intelligent` mode, which reads common data-layer keys for user ID, email, phone, first name, and last name
|
|
71
|
+
- `Custom` mode, which lets GTM explicitly map a main identity and traits
|
|
72
|
+
- `Disabled` mode, which skips identify entirely
|
|
73
|
+
|
|
74
|
+
### Generate GTM output
|
|
86
75
|
|
|
87
76
|
```ts
|
|
88
|
-
import {
|
|
77
|
+
import {
|
|
78
|
+
buildGtmTemplateArtifact,
|
|
79
|
+
buildGtmTemplateFileSource,
|
|
80
|
+
} from "@getuserfeedback/adapters/gtm";
|
|
89
81
|
|
|
90
82
|
const artifact = buildGtmTemplateArtifact({
|
|
91
83
|
loaderScriptBaseUrl: "https://cdn.getuserfeedback.com/widget/loader/v1",
|
|
92
84
|
});
|
|
93
85
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
const templateFile = buildGtmTemplateFileSource({
|
|
87
|
+
loaderScriptBaseUrl: "https://cdn.getuserfeedback.com/widget/loader/v1",
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Use the package script to write a local importable file:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
bun run generate:gtm-template
|
|
98
95
|
```
|
|
99
96
|
|
|
100
|
-
|
|
97
|
+
For the sandbox-backed GTM smoke:
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
bun run generate:gtm-template:sandbox-hybrid
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`buildGtmTemplateArtifact()` returns the rendered GTM sections. `buildGtmTemplateFileSource()` returns a full importable `template.tpl`.
|
|
101
104
|
|
|
102
105
|
### What the GTM repo should still own
|
|
103
106
|
|
|
104
107
|
After importing the published package, the GTM repo should only own:
|
|
105
108
|
|
|
106
|
-
- GTM Gallery wrapper file assembly
|
|
107
109
|
- brand thumbnail and base64 image assets
|
|
108
110
|
- `metadata.yaml`
|
|
109
111
|
- publishing and release workflow
|
|
110
112
|
|
|
111
|
-
It should not rebuild parameters, runtime source, permissions, or GTM-specific init payload translation.
|
|
113
|
+
It should not rebuild parameters, runtime source, permissions, file assembly, or GTM-specific init payload translation.
|
|
112
114
|
|
|
113
115
|
### Customizing the loader base URL
|
|
114
116
|
|
|
@@ -118,9 +120,12 @@ Pass `loaderScriptBaseUrl` to:
|
|
|
118
120
|
- `buildGtmPermissions`
|
|
119
121
|
- `buildGtmTemplateParts`
|
|
120
122
|
- `buildGtmTemplateArtifact`
|
|
123
|
+
- `buildGtmTemplateFileSource`
|
|
121
124
|
|
|
122
125
|
The same base URL is used to derive the runtime loader URL and the `inject_script` permission pattern.
|
|
123
126
|
|
|
127
|
+
Pass `runtimeEndpoints` when you need the generated template to point loader bootstrap at non-default `core` and `api` endpoints.
|
|
128
|
+
|
|
124
129
|
### Versioning expectations
|
|
125
130
|
|
|
126
131
|
Any change that affects generated GTM output is a public package change and should be versioned accordingly. This includes:
|
|
@@ -128,8 +133,8 @@ Any change that affects generated GTM output is a public package change and shou
|
|
|
128
133
|
- parameter shape or defaults
|
|
129
134
|
- runtime behavior
|
|
130
135
|
- permission generation
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
-
-
|
|
136
|
+
- color scheme normalization
|
|
137
|
+
- identity lookup behavior
|
|
138
|
+
- consent derivation behavior
|
|
134
139
|
|
|
135
140
|
Release notes should call out template-affecting changes explicitly.
|
package/dist/gtm/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type InitOptions
|
|
1
|
+
import { type InitOptions } from "@getuserfeedback/protocol";
|
|
2
2
|
export declare const GTM_CONSENT_TYPES: readonly [
|
|
3
3
|
"functionality_storage",
|
|
4
4
|
"security_storage",
|
|
@@ -10,17 +10,10 @@ export declare const GTM_CONSENT_TYPES: readonly [
|
|
|
10
10
|
];
|
|
11
11
|
export type GtmConsentType = (typeof GTM_CONSENT_TYPES)[number];
|
|
12
12
|
export type GtmConsentValue = "granted" | "denied";
|
|
13
|
-
export type GtmAnalyticsMeasurementMode = "inherit-analytics-storage" | "granted" | "denied";
|
|
14
|
-
export type GtmScopeMapping = {
|
|
15
|
-
scope: Scope;
|
|
16
|
-
consentType: GtmConsentType;
|
|
17
|
-
};
|
|
18
13
|
export type GtmConsentState = Partial<Record<GtmConsentType, GtmConsentValue>>;
|
|
19
14
|
export type GtmTemplateInput = {
|
|
20
15
|
apiKey: string;
|
|
21
16
|
consentState?: GtmConsentState;
|
|
22
|
-
scopeMappings?: ReadonlyArray<GtmScopeMapping>;
|
|
23
|
-
analyticsMeasurementMode?: GtmAnalyticsMeasurementMode;
|
|
24
17
|
colorScheme?: unknown;
|
|
25
18
|
disableTelemetry?: boolean;
|
|
26
19
|
enableDebug?: InitOptions["enableDebug"];
|
|
@@ -28,31 +21,10 @@ export type GtmTemplateInput = {
|
|
|
28
21
|
runtimeEndpoints?: InitOptions["runtimeEndpoints"];
|
|
29
22
|
clientMeta?: InitOptions["clientMeta"];
|
|
30
23
|
};
|
|
31
|
-
type ProtocolConsentScope = NonNullable<Exclude<InitOptions["defaultConsent"], string>>[number];
|
|
32
|
-
export type GtmTemplateScopeOption = {
|
|
33
|
-
label: string;
|
|
34
|
-
scope: Scope;
|
|
35
|
-
description: string;
|
|
36
|
-
};
|
|
37
|
-
export type GtmTemplateMappingOption = {
|
|
38
|
-
consentType: GtmConsentType;
|
|
39
|
-
label: string;
|
|
40
|
-
};
|
|
41
|
-
export declare const ESSENTIAL_GTM_SCOPES: readonly [
|
|
42
|
-
"functionality.storage",
|
|
43
|
-
"security.storage"
|
|
44
|
-
];
|
|
45
|
-
export declare const isHostConfigurableGtmScope: (scope: Scope) => scope is ProtocolConsentScope;
|
|
46
|
-
export declare const DEFAULT_GTM_SCOPE_MAPPINGS: ReadonlyArray<GtmScopeMapping>;
|
|
47
|
-
export declare const GTM_TEMPLATE_SCOPE_OPTIONS: ReadonlyArray<GtmTemplateScopeOption>;
|
|
48
|
-
export declare const GTM_TEMPLATE_MAPPING_OPTIONS: ReadonlyArray<GtmTemplateMappingOption>;
|
|
49
24
|
export declare function isGtmConsentType(value: unknown): value is GtmConsentType;
|
|
50
25
|
export declare function normalizeGtmThemeInput(input: unknown): InitOptions["colorScheme"] | undefined;
|
|
51
26
|
export declare function resolveDefaultConsentFromGtm(input: {
|
|
52
27
|
consentState?: GtmConsentState;
|
|
53
|
-
scopeMappings?: ReadonlyArray<GtmScopeMapping>;
|
|
54
|
-
analyticsMeasurementMode?: GtmAnalyticsMeasurementMode;
|
|
55
28
|
}): InitOptions["defaultConsent"] | undefined;
|
|
56
29
|
export declare function buildInitOptionsFromGtmTemplate(input: GtmTemplateInput): InitOptions;
|
|
57
|
-
export {};
|
|
58
30
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/gtm/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/gtm/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/gtm/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,WAAW,EAEhB,MAAM,2BAA2B,CAAC;AAEnC,eAAO,MAAM,iBAAiB,EAAE,SAAS;IACxC,uBAAuB;IACvB,kBAAkB;IAClB,mBAAmB;IACnB,yBAAyB;IACzB,YAAY;IACZ,cAAc;IACd,oBAAoB;CASpB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEnD,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;AAE/E,MAAM,MAAM,gBAAgB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IACzC,YAAY,CAAC,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IAC3C,gBAAgB,CAAC,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAC;IACnD,UAAU,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;CACvC,CAAC;AAQF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAKxE;AAED,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,OAAO,GACZ,WAAW,CAAC,aAAa,CAAC,GAAG,SAAS,CA2CxC;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE;IACnD,YAAY,CAAC,EAAE,eAAe,CAAC;CAC/B,GAAG,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS,CA0B5C;AAED,wBAAgB,+BAA+B,CAC9C,KAAK,EAAE,gBAAgB,GACrB,WAAW,CA4Bb"}
|
package/dist/gtm/core.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { colorSchemeConfigInputSchema, consentConfigInputSchema, DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS,
|
|
1
|
+
import { colorSchemeConfigInputSchema, consentConfigInputSchema, DEFAULT_AUTO_DETECT_COLOR_SCHEME_ATTRS, parseInitOptions, } from "@getuserfeedback/protocol";
|
|
2
2
|
export const GTM_CONSENT_TYPES = [
|
|
3
3
|
"functionality_storage",
|
|
4
4
|
"security_storage",
|
|
@@ -8,67 +8,10 @@ export const GTM_CONSENT_TYPES = [
|
|
|
8
8
|
"ad_user_data",
|
|
9
9
|
"ad_personalization",
|
|
10
10
|
];
|
|
11
|
-
export const ESSENTIAL_GTM_SCOPES = ["functionality.storage", "security.storage"];
|
|
12
|
-
const essentialScopes = new Set(ESSENTIAL_GTM_SCOPES);
|
|
13
|
-
export const isHostConfigurableGtmScope = (scope) => !essentialScopes.has(scope);
|
|
14
|
-
export const DEFAULT_GTM_SCOPE_MAPPINGS = [
|
|
15
|
-
{
|
|
16
|
-
scope: "functionality.storage",
|
|
17
|
-
consentType: "functionality_storage",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
scope: "security.storage",
|
|
21
|
-
consentType: "security_storage",
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
scope: "analytics.storage",
|
|
25
|
-
consentType: "analytics_storage",
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
scope: "personalization.storage",
|
|
29
|
-
consentType: "personalization_storage",
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
scope: "ads.storage",
|
|
33
|
-
consentType: "ad_storage",
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
scope: "ads.user_data",
|
|
37
|
-
consentType: "ad_user_data",
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
scope: "ads.personalization",
|
|
41
|
-
consentType: "ad_personalization",
|
|
42
|
-
},
|
|
43
|
-
];
|
|
44
|
-
const toTitleCase = (value) => value
|
|
45
|
-
.split(/[_\-.]/g)
|
|
46
|
-
.filter((part) => part.length > 0)
|
|
47
|
-
.map((part) => `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`)
|
|
48
|
-
.join(" ");
|
|
49
|
-
const uniqueScopes = (scopes) => {
|
|
50
|
-
const deduped = new Set();
|
|
51
|
-
for (const scope of scopes) {
|
|
52
|
-
if (!isHostConfigurableGtmScope(scope)) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
deduped.add(scope);
|
|
56
|
-
}
|
|
57
|
-
return [...deduped];
|
|
58
|
-
};
|
|
59
11
|
const normalizeAttrList = (value) => value
|
|
60
12
|
.split(",")
|
|
61
13
|
.map((entry) => entry.trim())
|
|
62
14
|
.filter((entry) => entry.length > 0);
|
|
63
|
-
export const GTM_TEMPLATE_SCOPE_OPTIONS = listScopes().map((scopeMeta) => ({
|
|
64
|
-
label: toTitleCase(scopeMeta.id),
|
|
65
|
-
scope: scopeMeta.id,
|
|
66
|
-
description: scopeMeta.description,
|
|
67
|
-
}));
|
|
68
|
-
export const GTM_TEMPLATE_MAPPING_OPTIONS = GTM_CONSENT_TYPES.map((consentType) => ({
|
|
69
|
-
consentType,
|
|
70
|
-
label: toTitleCase(consentType),
|
|
71
|
-
}));
|
|
72
15
|
export function isGtmConsentType(value) {
|
|
73
16
|
if (typeof value !== "string") {
|
|
74
17
|
return false;
|
|
@@ -119,27 +62,30 @@ export function resolveDefaultConsentFromGtm(input) {
|
|
|
119
62
|
if (!consentState) {
|
|
120
63
|
return undefined;
|
|
121
64
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
65
|
+
const grantedScopes = [];
|
|
66
|
+
if (consentState.analytics_storage === "granted") {
|
|
67
|
+
grantedScopes.push("analytics.storage", "analytics.measurement");
|
|
68
|
+
}
|
|
69
|
+
if (consentState.personalization_storage === "granted") {
|
|
70
|
+
grantedScopes.push("personalization.storage");
|
|
71
|
+
}
|
|
72
|
+
if (consentState.ad_storage === "granted") {
|
|
73
|
+
grantedScopes.push("ads.storage");
|
|
74
|
+
}
|
|
75
|
+
if (consentState.ad_user_data === "granted") {
|
|
76
|
+
grantedScopes.push("ads.user_data");
|
|
127
77
|
}
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
grantedScopes.push("analytics.measurement");
|
|
78
|
+
if (consentState.ad_personalization === "granted") {
|
|
79
|
+
grantedScopes.push("ads.personalization");
|
|
131
80
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
? consentConfigInputSchema.parse(normalizedGrantedScopes)
|
|
81
|
+
return grantedScopes.length > 0
|
|
82
|
+
? consentConfigInputSchema.parse(grantedScopes)
|
|
135
83
|
: undefined;
|
|
136
84
|
}
|
|
137
85
|
export function buildInitOptionsFromGtmTemplate(input) {
|
|
138
86
|
const colorScheme = normalizeGtmThemeInput(input.colorScheme);
|
|
139
87
|
const defaultConsent = resolveDefaultConsentFromGtm({
|
|
140
88
|
consentState: input.consentState,
|
|
141
|
-
scopeMappings: input.scopeMappings,
|
|
142
|
-
analyticsMeasurementMode: input.analyticsMeasurementMode,
|
|
143
89
|
});
|
|
144
90
|
return parseInitOptions({
|
|
145
91
|
apiKey: input.apiKey,
|
package/dist/gtm/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { buildInitOptionsFromGtmTemplate,
|
|
2
|
-
export { buildGtmPermissions, buildGtmRuntimeSource, buildGtmTemplateArtifact, buildGtmTemplateInfo, buildGtmTemplateParameters, buildGtmTemplateParts, DEFAULT_GTM_LOADER_SCRIPT_BASE_URL, type GtmTemplateArtifact, type GtmTemplateGenerationOptions, type GtmTemplateInfo, type GtmTemplateParts, type GtmTemplatePermission, type TemplateCondition, type TemplateParameter, type TemplateSelectItem, type TemplateValueValidator, } from "./template-generation.js";
|
|
1
|
+
export { buildInitOptionsFromGtmTemplate, GTM_CONSENT_TYPES, type GtmConsentState, type GtmConsentType, type GtmConsentValue, type GtmTemplateInput, isGtmConsentType, normalizeGtmThemeInput, resolveDefaultConsentFromGtm, } from "./core.js";
|
|
2
|
+
export { buildGtmPermissions, buildGtmRuntimeSource, buildGtmTemplateArtifact, buildGtmTemplateFileSource, buildGtmTemplateInfo, buildGtmTemplateParameters, buildGtmTemplateParts, DEFAULT_GTM_LOADER_SCRIPT_BASE_URL, type GtmTemplateArtifact, type GtmTemplateFileInfoOverrides, type GtmTemplateFileOptions, type GtmTemplateGenerationOptions, type GtmTemplateInfo, type GtmTemplateParts, type GtmTemplatePermission, type TemplateCondition, type TemplateParameter, type TemplateSelectItem, type TemplateValueValidator, } from "./template-generation.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/gtm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gtm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,+BAA+B,EAC/B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gtm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,+BAA+B,EAC/B,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,4BAA4B,GAC5B,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,oBAAoB,EACpB,0BAA0B,EAC1B,qBAAqB,EACrB,kCAAkC,EAClC,KAAK,mBAAmB,EACxB,KAAK,4BAA4B,EACjC,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,GAC3B,MAAM,0BAA0B,CAAC"}
|
package/dist/gtm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { buildInitOptionsFromGtmTemplate,
|
|
2
|
-
export { buildGtmPermissions, buildGtmRuntimeSource, buildGtmTemplateArtifact, buildGtmTemplateInfo, buildGtmTemplateParameters, buildGtmTemplateParts, DEFAULT_GTM_LOADER_SCRIPT_BASE_URL, } from "./template-generation.js";
|
|
1
|
+
export { buildInitOptionsFromGtmTemplate, GTM_CONSENT_TYPES, isGtmConsentType, normalizeGtmThemeInput, resolveDefaultConsentFromGtm, } from "./core.js";
|
|
2
|
+
export { buildGtmPermissions, buildGtmRuntimeSource, buildGtmTemplateArtifact, buildGtmTemplateFileSource, buildGtmTemplateInfo, buildGtmTemplateParameters, buildGtmTemplateParts, DEFAULT_GTM_LOADER_SCRIPT_BASE_URL, } from "./template-generation.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PublicCommandPayload } from "@getuserfeedback/protocol";
|
|
2
|
+
export declare const GTM_QUEUE_CLIENT_META: {
|
|
3
|
+
loader: string;
|
|
4
|
+
transport: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const RESOLVE_GTM_THEME_INPUT_FROM_TEMPLATE_DATA_SOURCE = "function resolveGtmThemeInputFromTemplateData(templateData) {\n\tif (templateData.themeMode === \"variable\") {\n\t\treturn templateData.themeModeVariable;\n\t}\n\tif (templateData.themeMode === \"host\") {\n\t\treturn templateData.themeAttr;\n\t}\n\treturn templateData.themeMode === \"light\" ||\n\t\ttemplateData.themeMode === \"dark\" ||\n\t\ttemplateData.themeMode === \"system\"\n\t\t? templateData.themeMode\n\t\t: undefined;\n}";
|
|
7
|
+
export declare const BUILD_GTM_IDENTIFY_COMMAND_SOURCE = "function buildGtmIdentifyCommand(input) {\n\tfunction normalizeTraitValue(value) {\n\t\tif (value === undefined || value === null) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (typeof value !== \"string\") {\n\t\t\treturn value;\n\t\t}\n\t\tconst trimmedValue = value.trim();\n\t\treturn trimmedValue.length > 0 ? trimmedValue : undefined;\n\t}\n\n\tfunction normalizeUserIdValue(value) {\n\t\tif (typeof value !== \"string\") {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst trimmedValue = value.trim();\n\t\treturn trimmedValue.length > 0 ? trimmedValue : undefined;\n\t}\n\n\tfunction addTrait(traits, name, value) {\n\t\tconst traitName = name.trim();\n\t\tconst traitValue = normalizeTraitValue(value);\n\t\tif (traitName.length === 0 || traitValue === undefined) {\n\t\t\treturn;\n\t\t}\n\t\ttraits[traitName] = traitValue;\n\t}\n\n\tfunction hasOwnKeys(value) {\n\t\tfor (const key in value) {\n\t\t\treturn key.length > 0;\n\t\t}\n\t\treturn false;\n\t}\n\n\tfunction buildFromUserIdAndTraits(userId, traits) {\n\t\tconst hasTraits = hasOwnKeys(traits);\n\t\tif (userId && hasTraits) {\n\t\t\treturn {\n\t\t\t\tkind: \"identify\",\n\t\t\t\tuserId: userId,\n\t\t\t\ttraits: traits,\n\t\t\t};\n\t\t}\n\t\tif (userId) {\n\t\t\treturn {\n\t\t\t\tkind: \"identify\",\n\t\t\t\tuserId: userId,\n\t\t\t};\n\t\t}\n\t\tif (hasTraits) {\n\t\t\treturn {\n\t\t\t\tkind: \"identify\",\n\t\t\t\ttraits: traits,\n\t\t\t};\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tif (input.mode === \"disabled\") {\n\t\treturn undefined;\n\t}\n\n\tif (input.mode === \"intelligent\") {\n\t\tconst traits = {};\n\t\taddTrait(traits, \"email\", input.email);\n\t\taddTrait(traits, \"firstName\", input.firstName);\n\t\taddTrait(traits, \"lastName\", input.lastName);\n\t\taddTrait(traits, \"phone\", input.phone);\n\t\treturn buildFromUserIdAndTraits(normalizeUserIdValue(input.userId), traits);\n\t}\n\n\tconst traits = {};\n\tif (input.traits && typeof input.traits === \"object\") {\n\t\tfor (const key in input.traits) {\n\t\t\ttraits[key] = input.traits[key];\n\t\t}\n\t}\n\tif (input.primaryIdentityType === \"userId\") {\n\t\treturn buildFromUserIdAndTraits(\n\t\t\tnormalizeUserIdValue(input.primaryIdentityValue),\n\t\t\ttraits,\n\t\t);\n\t}\n\n\tif (\n\t\tinput.primaryIdentityType === \"email\" ||\n\t\tinput.primaryIdentityType === \"phone\"\n\t) {\n\t\taddTrait(traits, input.primaryIdentityType, input.primaryIdentityValue);\n\t}\n\n\treturn hasOwnKeys(traits)\n\t\t? {\n\t\t\t\tkind: \"identify\",\n\t\t\t\ttraits: traits,\n\t\t\t}\n\t\t: undefined;\n}";
|
|
8
|
+
export type GtmIdentifyCommand = Extract<PublicCommandPayload, {
|
|
9
|
+
kind: "identify";
|
|
10
|
+
}>;
|
|
11
|
+
export type GtmIdentifyCommandInput = {
|
|
12
|
+
mode: "advanced" | "intelligent" | "disabled";
|
|
13
|
+
userId?: unknown;
|
|
14
|
+
email?: unknown;
|
|
15
|
+
firstName?: unknown;
|
|
16
|
+
lastName?: unknown;
|
|
17
|
+
phone?: unknown;
|
|
18
|
+
primaryIdentityType?: unknown;
|
|
19
|
+
primaryIdentityValue?: unknown;
|
|
20
|
+
traits?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
export declare function resolveGtmThemeInputFromTemplateData(templateData: {
|
|
23
|
+
themeMode?: unknown;
|
|
24
|
+
themeModeVariable?: unknown;
|
|
25
|
+
themeAttr?: unknown;
|
|
26
|
+
}): unknown;
|
|
27
|
+
export declare function buildGtmIdentifyCommand(input: GtmIdentifyCommandInput): GtmIdentifyCommand | undefined;
|
|
28
|
+
//# sourceMappingURL=runtime-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-model.d.ts","sourceRoot":"","sources":["../../src/gtm/runtime-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE,eAAO,MAAM,qBAAqB;;;CAGjC,CAAC;AAEF,eAAO,MAAM,iDAAiD,wbAY5D,CAAC;AAEH,eAAO,MAAM,iCAAiC,y+EAmG5C,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACvC,oBAAoB,EACpB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACrC,IAAI,EAAE,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC;IAC9C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAAC;AAEF,wBAAgB,oCAAoC,CAAC,YAAY,EAAE;IAClE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,OAAO,CAYV;AAED,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,uBAAuB,GAC5B,kBAAkB,GAAG,SAAS,CA0GhC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
export const GTM_QUEUE_CLIENT_META = {
|
|
2
|
+
loader: "gtm",
|
|
3
|
+
transport: "tag-manager",
|
|
4
|
+
};
|
|
5
|
+
export const RESOLVE_GTM_THEME_INPUT_FROM_TEMPLATE_DATA_SOURCE = `function resolveGtmThemeInputFromTemplateData(templateData) {
|
|
6
|
+
if (templateData.themeMode === "variable") {
|
|
7
|
+
return templateData.themeModeVariable;
|
|
8
|
+
}
|
|
9
|
+
if (templateData.themeMode === "host") {
|
|
10
|
+
return templateData.themeAttr;
|
|
11
|
+
}
|
|
12
|
+
return templateData.themeMode === "light" ||
|
|
13
|
+
templateData.themeMode === "dark" ||
|
|
14
|
+
templateData.themeMode === "system"
|
|
15
|
+
? templateData.themeMode
|
|
16
|
+
: undefined;
|
|
17
|
+
}`;
|
|
18
|
+
export const BUILD_GTM_IDENTIFY_COMMAND_SOURCE = `function buildGtmIdentifyCommand(input) {
|
|
19
|
+
function normalizeTraitValue(value) {
|
|
20
|
+
if (value === undefined || value === null) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (typeof value !== "string") {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
const trimmedValue = value.trim();
|
|
27
|
+
return trimmedValue.length > 0 ? trimmedValue : undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function normalizeUserIdValue(value) {
|
|
31
|
+
if (typeof value !== "string") {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const trimmedValue = value.trim();
|
|
35
|
+
return trimmedValue.length > 0 ? trimmedValue : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function addTrait(traits, name, value) {
|
|
39
|
+
const traitName = name.trim();
|
|
40
|
+
const traitValue = normalizeTraitValue(value);
|
|
41
|
+
if (traitName.length === 0 || traitValue === undefined) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
traits[traitName] = traitValue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function hasOwnKeys(value) {
|
|
48
|
+
for (const key in value) {
|
|
49
|
+
return key.length > 0;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function buildFromUserIdAndTraits(userId, traits) {
|
|
55
|
+
const hasTraits = hasOwnKeys(traits);
|
|
56
|
+
if (userId && hasTraits) {
|
|
57
|
+
return {
|
|
58
|
+
kind: "identify",
|
|
59
|
+
userId: userId,
|
|
60
|
+
traits: traits,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (userId) {
|
|
64
|
+
return {
|
|
65
|
+
kind: "identify",
|
|
66
|
+
userId: userId,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (hasTraits) {
|
|
70
|
+
return {
|
|
71
|
+
kind: "identify",
|
|
72
|
+
traits: traits,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (input.mode === "disabled") {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (input.mode === "intelligent") {
|
|
83
|
+
const traits = {};
|
|
84
|
+
addTrait(traits, "email", input.email);
|
|
85
|
+
addTrait(traits, "firstName", input.firstName);
|
|
86
|
+
addTrait(traits, "lastName", input.lastName);
|
|
87
|
+
addTrait(traits, "phone", input.phone);
|
|
88
|
+
return buildFromUserIdAndTraits(normalizeUserIdValue(input.userId), traits);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const traits = {};
|
|
92
|
+
if (input.traits && typeof input.traits === "object") {
|
|
93
|
+
for (const key in input.traits) {
|
|
94
|
+
traits[key] = input.traits[key];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (input.primaryIdentityType === "userId") {
|
|
98
|
+
return buildFromUserIdAndTraits(
|
|
99
|
+
normalizeUserIdValue(input.primaryIdentityValue),
|
|
100
|
+
traits,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (
|
|
105
|
+
input.primaryIdentityType === "email" ||
|
|
106
|
+
input.primaryIdentityType === "phone"
|
|
107
|
+
) {
|
|
108
|
+
addTrait(traits, input.primaryIdentityType, input.primaryIdentityValue);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return hasOwnKeys(traits)
|
|
112
|
+
? {
|
|
113
|
+
kind: "identify",
|
|
114
|
+
traits: traits,
|
|
115
|
+
}
|
|
116
|
+
: undefined;
|
|
117
|
+
}`;
|
|
118
|
+
export function resolveGtmThemeInputFromTemplateData(templateData) {
|
|
119
|
+
if (templateData.themeMode === "variable") {
|
|
120
|
+
return templateData.themeModeVariable;
|
|
121
|
+
}
|
|
122
|
+
if (templateData.themeMode === "host") {
|
|
123
|
+
return templateData.themeAttr;
|
|
124
|
+
}
|
|
125
|
+
return templateData.themeMode === "light" ||
|
|
126
|
+
templateData.themeMode === "dark" ||
|
|
127
|
+
templateData.themeMode === "system"
|
|
128
|
+
? templateData.themeMode
|
|
129
|
+
: undefined;
|
|
130
|
+
}
|
|
131
|
+
export function buildGtmIdentifyCommand(input) {
|
|
132
|
+
function normalizeTraitValue(value) {
|
|
133
|
+
if (value === undefined || value === null) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
if (typeof value !== "string") {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
const trimmedValue = value.trim();
|
|
140
|
+
return trimmedValue.length > 0 ? trimmedValue : undefined;
|
|
141
|
+
}
|
|
142
|
+
function normalizeUserIdValue(value) {
|
|
143
|
+
if (typeof value !== "string") {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const trimmedValue = value.trim();
|
|
147
|
+
return trimmedValue.length > 0 ? trimmedValue : undefined;
|
|
148
|
+
}
|
|
149
|
+
function addTrait(traits, name, value) {
|
|
150
|
+
const traitName = name.trim();
|
|
151
|
+
const traitValue = normalizeTraitValue(value);
|
|
152
|
+
if (traitName.length === 0 || traitValue === undefined) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
traits[traitName] = traitValue;
|
|
156
|
+
}
|
|
157
|
+
function hasOwnKeys(value) {
|
|
158
|
+
for (const key in value) {
|
|
159
|
+
return key.length > 0;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
function buildFromUserIdAndTraits(userId, traits) {
|
|
164
|
+
const hasTraits = hasOwnKeys(traits);
|
|
165
|
+
if (userId && hasTraits) {
|
|
166
|
+
return {
|
|
167
|
+
kind: "identify",
|
|
168
|
+
userId,
|
|
169
|
+
traits,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (userId) {
|
|
173
|
+
return {
|
|
174
|
+
kind: "identify",
|
|
175
|
+
userId,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (hasTraits) {
|
|
179
|
+
return {
|
|
180
|
+
kind: "identify",
|
|
181
|
+
traits,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
if (input.mode === "disabled") {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
if (input.mode === "intelligent") {
|
|
190
|
+
const traits = {};
|
|
191
|
+
addTrait(traits, "email", input.email);
|
|
192
|
+
addTrait(traits, "firstName", input.firstName);
|
|
193
|
+
addTrait(traits, "lastName", input.lastName);
|
|
194
|
+
addTrait(traits, "phone", input.phone);
|
|
195
|
+
return buildFromUserIdAndTraits(normalizeUserIdValue(input.userId), traits);
|
|
196
|
+
}
|
|
197
|
+
const traits = {};
|
|
198
|
+
if (input.traits && typeof input.traits === "object") {
|
|
199
|
+
for (const key in input.traits) {
|
|
200
|
+
traits[key] = input.traits[key];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (input.primaryIdentityType === "userId") {
|
|
204
|
+
return buildFromUserIdAndTraits(normalizeUserIdValue(input.primaryIdentityValue), traits);
|
|
205
|
+
}
|
|
206
|
+
if (input.primaryIdentityType === "email" ||
|
|
207
|
+
input.primaryIdentityType === "phone") {
|
|
208
|
+
addTrait(traits, input.primaryIdentityType, input.primaryIdentityValue);
|
|
209
|
+
}
|
|
210
|
+
return hasOwnKeys(traits)
|
|
211
|
+
? {
|
|
212
|
+
kind: "identify",
|
|
213
|
+
traits,
|
|
214
|
+
}
|
|
215
|
+
: undefined;
|
|
216
|
+
}
|
|
@@ -120,8 +120,29 @@ export type GtmTemplateParts = {
|
|
|
120
120
|
permissions: GtmTemplatePermission[];
|
|
121
121
|
};
|
|
122
122
|
export type GtmTemplateArtifact = GtmTemplateParts;
|
|
123
|
+
export type GtmTemplateFileInfoOverrides = {
|
|
124
|
+
id?: string;
|
|
125
|
+
securityGroups?: ReadonlyArray<string>;
|
|
126
|
+
brandDisplayName?: string;
|
|
127
|
+
brandThumbnail?: string;
|
|
128
|
+
categories?: ReadonlyArray<string>;
|
|
129
|
+
displayName?: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
};
|
|
132
|
+
export type GtmTemplateFileOptions = GtmTemplateGenerationOptions & {
|
|
133
|
+
includeUtf8Bom?: boolean;
|
|
134
|
+
infoOverrides?: GtmTemplateFileInfoOverrides;
|
|
135
|
+
termsOfService?: string;
|
|
136
|
+
tests?: string;
|
|
137
|
+
notes?: string;
|
|
138
|
+
};
|
|
123
139
|
export type GtmTemplateGenerationOptions = {
|
|
140
|
+
additionalLoaderScriptUrlPatterns?: string[];
|
|
124
141
|
loaderScriptBaseUrl?: string;
|
|
142
|
+
runtimeEndpoints?: {
|
|
143
|
+
apiUrl: string;
|
|
144
|
+
coreUrl: string;
|
|
145
|
+
};
|
|
125
146
|
displayName?: string;
|
|
126
147
|
description?: string;
|
|
127
148
|
};
|
|
@@ -132,5 +153,6 @@ export declare function buildGtmPermissions(input?: GtmTemplateGenerationOptions
|
|
|
132
153
|
export declare function buildGtmTemplateInfo(input?: GtmTemplateGenerationOptions): GtmTemplateInfo;
|
|
133
154
|
export declare function buildGtmTemplateParts(input?: GtmTemplateGenerationOptions): GtmTemplateParts;
|
|
134
155
|
export declare function buildGtmTemplateArtifact(input?: GtmTemplateGenerationOptions): GtmTemplateArtifact;
|
|
156
|
+
export declare function buildGtmTemplateFileSource(input?: GtmTemplateFileOptions): string;
|
|
135
157
|
export {};
|
|
136
158
|
//# sourceMappingURL=template-generation.d.ts.map
|