@revenexx/cover 0.19.0 → 0.20.0
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/app/api/marketing.ts +24 -0
- package/app/app.config.ts +22 -0
- package/app/components/account/loyalty/AccountLoyalty.vue +205 -0
- package/app/components/cart/view/CartSummaryPanel.vue +4 -0
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +4 -0
- package/app/components/loyalty/hint/LoyaltyPerkHint.vue +28 -0
- package/app/components/newsletter/confirm/NewsletterConfirmation.vue +54 -0
- package/app/components/newsletter/preferences/NewsletterPreferenceCentre.vue +183 -0
- package/app/components/newsletter/state/NewsletterLinkRefusal.vue +45 -0
- package/app/components/review/form/ReviewForm.vue +211 -0
- package/app/composables/useCampaignAttribution.ts +120 -0
- package/app/composables/useCheckoutOnePage.ts +9 -0
- package/app/composables/useLoyaltyAccount.ts +79 -0
- package/app/composables/useMarketingConsent.ts +49 -0
- package/app/config/navigation.ts +1 -1
- package/app/config/quickActions.ts +1 -0
- package/app/pages/account/points.vue +26 -0
- package/app/pages/newsletter/confirm/[token].vue +23 -0
- package/app/pages/newsletter/preferences/[token].vue +24 -0
- package/app/pages/review/[token].vue +23 -0
- package/app/plugins/campaign-attribution.client.ts +47 -0
- package/app/shared/campaignAttribution.ts +281 -0
- package/app/shared/personalisation.ts +107 -0
- package/i18n/locales/de/account.json +3 -2
- package/i18n/locales/de/marketing.json +71 -0
- package/i18n/locales/en/account.json +3 -2
- package/i18n/locales/en/marketing.json +71 -0
- package/package.json +1 -1
- package/server/api/campaigns/touches.post.ts +42 -0
- package/server/api/cart/attribution.put.ts +31 -0
- package/server/api/loyalty/account.get.ts +27 -0
- package/server/api/newsletter/confirm/[token].post.ts +21 -0
- package/server/api/newsletter/preferences/[token].get.ts +14 -0
- package/server/api/newsletter/preferences/[token].post.ts +36 -0
- package/server/api/orders/index.post.ts +10 -1
- package/server/api/reviews/requests/[token].get.ts +14 -0
- package/server/api/reviews/submit/[token].post.ts +31 -0
- package/server/interfaces/cart.ts +6 -0
- package/server/interfaces/marketing.ts +150 -0
- package/server/services/ApiCartService.ts +16 -0
- package/server/services/ApiMarketingService.ts +292 -0
- package/server/services/MockMarketingService.ts +178 -0
- package/server/utils/marketingService.ts +63 -0
- package/server/utils/orderAttribution.ts +65 -0
- package/server/utils/personalisationViewer.ts +28 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a visit came from (RAD-293): the UTM parameters and the ad click id a
|
|
3
|
+
* visitor landed with, first and last touch, and the consent in force — the
|
|
4
|
+
* `attribution` object the carts and orders apps keep (marketing contracts
|
|
5
|
+
* §4.3). Pure, so the browser that collects it and the BFF that forwards it
|
|
6
|
+
* hold one rule.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here decides consent. The caller only builds or keeps a touch once
|
|
9
|
+
* the visitor allowed the statistics or the marketing purpose; a click id is
|
|
10
|
+
* kept only under the marketing purpose, because it exists to tell an ad
|
|
11
|
+
* platform about the visitor.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const ATTRIBUTION_STORAGE_KEY = "rvx:attribution";
|
|
15
|
+
|
|
16
|
+
/** A first touch older than this starts over: a campaign weeks ago did not bring today's order. */
|
|
17
|
+
export const ATTRIBUTION_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
|
|
18
|
+
|
|
19
|
+
export const UTM_FIELDS = ["utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term"] as const;
|
|
20
|
+
export const CLICK_ID_KINDS = ["gclid", "fbclid", "li_fat_id", "msclkid"] as const;
|
|
21
|
+
|
|
22
|
+
export type UtmField = typeof UTM_FIELDS[number];
|
|
23
|
+
export type ClickIdKind = typeof CLICK_ID_KINDS[number];
|
|
24
|
+
|
|
25
|
+
/** What one landing brought: only the fields that were in the address. */
|
|
26
|
+
export interface LandingTouch {
|
|
27
|
+
utm: Partial<Record<UtmField, string>>;
|
|
28
|
+
click_id?: string;
|
|
29
|
+
click_id_kind?: ClickIdKind;
|
|
30
|
+
landing_url: string;
|
|
31
|
+
referrer: string | null;
|
|
32
|
+
at: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** What the browser keeps between landings. */
|
|
36
|
+
export interface StoredAttribution {
|
|
37
|
+
utm: Partial<Record<UtmField, string>>;
|
|
38
|
+
click_id?: string;
|
|
39
|
+
click_id_kind?: ClickIdKind;
|
|
40
|
+
landing_url: string;
|
|
41
|
+
referrer: string | null;
|
|
42
|
+
first_touch_at: string;
|
|
43
|
+
last_touch_at: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The consent half of the object, as the consent manager decided it. */
|
|
47
|
+
export interface AttributionConsent {
|
|
48
|
+
ads: boolean;
|
|
49
|
+
analytics: boolean;
|
|
50
|
+
policy_version: string | null;
|
|
51
|
+
purposes: string[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The closed shape the carts and orders apps accept. */
|
|
55
|
+
export interface Attribution {
|
|
56
|
+
utm_source: string | null;
|
|
57
|
+
utm_medium: string | null;
|
|
58
|
+
utm_campaign: string | null;
|
|
59
|
+
utm_content: string | null;
|
|
60
|
+
utm_term: string | null;
|
|
61
|
+
campaign_ref: string | null;
|
|
62
|
+
click_id: string | null;
|
|
63
|
+
click_id_kind: ClickIdKind | null;
|
|
64
|
+
landing_url: string | null;
|
|
65
|
+
referrer: string | null;
|
|
66
|
+
first_touch_at: string | null;
|
|
67
|
+
last_touch_at: string | null;
|
|
68
|
+
consent: AttributionConsent | null;
|
|
69
|
+
objection_notice_shown: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const MAX_TEXT = 500;
|
|
73
|
+
const MAX_URL = 2048;
|
|
74
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
75
|
+
const PURPOSE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
76
|
+
|
|
77
|
+
function clip(value: unknown, max: number): string | null {
|
|
78
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const text = String(value).trim();
|
|
82
|
+
return text ? text.slice(0, max) : null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The address without anything personal a link could carry: no fragment, and
|
|
87
|
+
* only the campaign parameters of the query. A newsletter link may carry a
|
|
88
|
+
* token or an address; the landing URL is copied into every order.
|
|
89
|
+
*/
|
|
90
|
+
export function cleanLandingUrl(url: URL): string {
|
|
91
|
+
const clean = new URL(url.origin + url.pathname);
|
|
92
|
+
for (const key of [...UTM_FIELDS, ...CLICK_ID_KINDS]) {
|
|
93
|
+
const value = url.searchParams.get(key);
|
|
94
|
+
if (value) {
|
|
95
|
+
clean.searchParams.set(key, value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return clean.toString().slice(0, MAX_URL);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** A referrer reduced to its origin; the shop's own pages are no referrer at all. */
|
|
102
|
+
export function cleanReferrer(referrer: string | null | undefined, ownOrigin: string): string | null {
|
|
103
|
+
if (!referrer) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const origin = new URL(referrer).origin;
|
|
108
|
+
return origin === ownOrigin || origin === "null" ? null : origin;
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The touch an address brings, or null when it carries no campaign: a plain
|
|
117
|
+
* visit to the shop is not a touch, and must not overwrite the last campaign.
|
|
118
|
+
*/
|
|
119
|
+
export function landingTouchOf(url: URL, referrer: string | null | undefined, at: Date): LandingTouch | null {
|
|
120
|
+
const utm: Partial<Record<UtmField, string>> = {};
|
|
121
|
+
for (const field of UTM_FIELDS) {
|
|
122
|
+
const value = clip(url.searchParams.get(field), MAX_TEXT);
|
|
123
|
+
if (value) {
|
|
124
|
+
utm[field] = value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
let click: { click_id: string; click_id_kind: ClickIdKind } | null = null;
|
|
128
|
+
for (const kind of CLICK_ID_KINDS) {
|
|
129
|
+
const value = clip(url.searchParams.get(kind), MAX_TEXT);
|
|
130
|
+
if (value) {
|
|
131
|
+
click = { click_id: value, click_id_kind: kind };
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (!Object.keys(utm).length && !click) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
utm,
|
|
140
|
+
...(click ?? {}),
|
|
141
|
+
landing_url: cleanLandingUrl(url),
|
|
142
|
+
referrer: cleanReferrer(referrer, url.origin),
|
|
143
|
+
at: at.toISOString(),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A new touch over what was kept: the campaign fields are the last touch's,
|
|
149
|
+
* the first touch's time survives — unless what was kept is too old to count.
|
|
150
|
+
* A click id only travels when ads are allowed.
|
|
151
|
+
*/
|
|
152
|
+
export function mergeTouch(
|
|
153
|
+
stored: StoredAttribution | null,
|
|
154
|
+
touch: LandingTouch,
|
|
155
|
+
options: { allowClickId: boolean },
|
|
156
|
+
): StoredAttribution {
|
|
157
|
+
const fresh = !stored || Date.parse(touch.at) - Date.parse(stored.first_touch_at) > ATTRIBUTION_MAX_AGE_MS;
|
|
158
|
+
const click = options.allowClickId && touch.click_id && touch.click_id_kind
|
|
159
|
+
? { click_id: touch.click_id, click_id_kind: touch.click_id_kind }
|
|
160
|
+
: {};
|
|
161
|
+
return {
|
|
162
|
+
utm: { ...touch.utm },
|
|
163
|
+
...click,
|
|
164
|
+
landing_url: touch.landing_url,
|
|
165
|
+
referrer: touch.referrer,
|
|
166
|
+
first_touch_at: fresh ? touch.at : stored!.first_touch_at,
|
|
167
|
+
last_touch_at: touch.at,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** What is kept, read back defensively: storage is the visitor's, and may hold anything. */
|
|
172
|
+
export function parseStoredAttribution(raw: string | null, now: Date): StoredAttribution | null {
|
|
173
|
+
if (!raw) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
const value = JSON.parse(raw) as StoredAttribution;
|
|
178
|
+
if (!value || typeof value !== "object" || typeof value.first_touch_at !== "string" || typeof value.last_touch_at !== "string") {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
if (now.getTime() - Date.parse(value.first_touch_at) > ATTRIBUTION_MAX_AGE_MS) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
return value;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Without the click id — what is left once ads are no longer allowed. */
|
|
192
|
+
export function withoutClickId(stored: StoredAttribution): StoredAttribution {
|
|
193
|
+
const { click_id: _id, click_id_kind: _kind, ...rest } = stored;
|
|
194
|
+
return rest;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The object the cart and the order are given. */
|
|
198
|
+
export function toAttribution(
|
|
199
|
+
stored: StoredAttribution,
|
|
200
|
+
consent: AttributionConsent,
|
|
201
|
+
options: { objectionNoticeShown?: boolean } = {},
|
|
202
|
+
): Attribution {
|
|
203
|
+
const click = consent.ads && stored.click_id && stored.click_id_kind
|
|
204
|
+
? { click_id: stored.click_id, click_id_kind: stored.click_id_kind }
|
|
205
|
+
: { click_id: null, click_id_kind: null };
|
|
206
|
+
return {
|
|
207
|
+
utm_source: stored.utm.utm_source ?? null,
|
|
208
|
+
utm_medium: stored.utm.utm_medium ?? null,
|
|
209
|
+
utm_campaign: stored.utm.utm_campaign ?? null,
|
|
210
|
+
utm_content: stored.utm.utm_content ?? null,
|
|
211
|
+
utm_term: stored.utm.utm_term ?? null,
|
|
212
|
+
campaign_ref: null,
|
|
213
|
+
...click,
|
|
214
|
+
landing_url: stored.landing_url,
|
|
215
|
+
referrer: stored.referrer,
|
|
216
|
+
first_touch_at: stored.first_touch_at,
|
|
217
|
+
last_touch_at: stored.last_touch_at,
|
|
218
|
+
consent,
|
|
219
|
+
objection_notice_shown: options.objectionNoticeShown === true,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The attribution as the BFF forwards it, or null. Whatever a browser sent is
|
|
225
|
+
* rebuilt into the closed shape: an unknown key or a malformed value would be
|
|
226
|
+
* a 400 from the carts or orders app, and an order must never fail over where
|
|
227
|
+
* its buyer came from. Without a consent that allows statistics or marketing
|
|
228
|
+
* there is nothing to forward.
|
|
229
|
+
*/
|
|
230
|
+
export function sanitizeAttribution(raw: unknown): Attribution | null {
|
|
231
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
const input = raw as Record<string, unknown>;
|
|
235
|
+
const consentIn = input.consent && typeof input.consent === "object" && !Array.isArray(input.consent)
|
|
236
|
+
? input.consent as Record<string, unknown>
|
|
237
|
+
: null;
|
|
238
|
+
if (!consentIn) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
const purposes = Array.isArray(consentIn.purposes)
|
|
242
|
+
? [...new Set(consentIn.purposes
|
|
243
|
+
.filter((p): p is string => typeof p === "string")
|
|
244
|
+
.map(p => p.trim().toLowerCase())
|
|
245
|
+
.filter(p => PURPOSE.test(p)))].slice(0, 20)
|
|
246
|
+
: [];
|
|
247
|
+
const consent: AttributionConsent = {
|
|
248
|
+
ads: consentIn.ads === true,
|
|
249
|
+
analytics: consentIn.analytics === true,
|
|
250
|
+
policy_version: clip(consentIn.policy_version, 64),
|
|
251
|
+
purposes,
|
|
252
|
+
};
|
|
253
|
+
if (!consent.ads && !consent.analytics) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
const time = (value: unknown): string | null => {
|
|
257
|
+
const text = clip(value, 64);
|
|
258
|
+
return text && !Number.isNaN(Date.parse(text)) ? new Date(text).toISOString() : null;
|
|
259
|
+
};
|
|
260
|
+
const kind = typeof input.click_id_kind === "string" && (CLICK_ID_KINDS as readonly string[]).includes(input.click_id_kind)
|
|
261
|
+
? input.click_id_kind as ClickIdKind
|
|
262
|
+
: null;
|
|
263
|
+
const clickId = consent.ads && kind ? clip(input.click_id, MAX_TEXT) : null;
|
|
264
|
+
const ref = clip(input.campaign_ref, 64);
|
|
265
|
+
return {
|
|
266
|
+
utm_source: clip(input.utm_source, MAX_TEXT),
|
|
267
|
+
utm_medium: clip(input.utm_medium, MAX_TEXT),
|
|
268
|
+
utm_campaign: clip(input.utm_campaign, MAX_TEXT),
|
|
269
|
+
utm_content: clip(input.utm_content, MAX_TEXT),
|
|
270
|
+
utm_term: clip(input.utm_term, MAX_TEXT),
|
|
271
|
+
campaign_ref: ref && UUID.test(ref) ? ref : null,
|
|
272
|
+
click_id: clickId,
|
|
273
|
+
click_id_kind: clickId ? kind : null,
|
|
274
|
+
landing_url: clip(input.landing_url, MAX_URL),
|
|
275
|
+
referrer: clip(input.referrer, MAX_URL),
|
|
276
|
+
first_touch_at: time(input.first_touch_at),
|
|
277
|
+
last_touch_at: time(input.last_touch_at),
|
|
278
|
+
consent,
|
|
279
|
+
objection_notice_shown: input.objection_notice_shown === true,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onsite personalisation (RAD-293, marketing contracts §4.5): who may see a
|
|
3
|
+
* content block or a pop-up, decided by the audiences a signed-in contact is
|
|
4
|
+
* in and the purposes the visitor allowed in the cookie choice.
|
|
5
|
+
*
|
|
6
|
+
* The pages app applies the same rule when it delivers a live page; this copy
|
|
7
|
+
* serves the shop's local content, so a demo and a test behave as a deployed
|
|
8
|
+
* shop does.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface BlockVisibility {
|
|
12
|
+
audiences?: string[];
|
|
13
|
+
exclude_audiences?: string[];
|
|
14
|
+
consent_purpose?: string | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Who is looking: audience codes (empty for anonymous) and allowed purposes. */
|
|
18
|
+
export interface Viewer {
|
|
19
|
+
audiences: string[];
|
|
20
|
+
consents: string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const CODE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
24
|
+
|
|
25
|
+
/** A comma list or an array of codes, lower-cased, without anything malformed. */
|
|
26
|
+
export function codeList(value: unknown): string[] {
|
|
27
|
+
if (value === undefined || value === null) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const list = Array.isArray(value) ? value : String(value).split(",");
|
|
31
|
+
const out: string[] = [];
|
|
32
|
+
for (const raw of list) {
|
|
33
|
+
const code = String(raw ?? "").trim().toLowerCase();
|
|
34
|
+
if (code && CODE.test(code) && !out.includes(code)) {
|
|
35
|
+
out.push(code);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Whether a viewer is shown something with this visibility. No rule — visible to all. */
|
|
42
|
+
export function visibleTo(visibility: unknown, viewer: Viewer): boolean {
|
|
43
|
+
if (!visibility || typeof visibility !== "object" || Array.isArray(visibility)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
const rule = visibility as BlockVisibility;
|
|
47
|
+
const audiences = codeList(rule.audiences);
|
|
48
|
+
const excluded = codeList(rule.exclude_audiences);
|
|
49
|
+
const purpose = typeof rule.consent_purpose === "string" ? rule.consent_purpose.trim().toLowerCase() : "";
|
|
50
|
+
if (audiences.length && !audiences.some(a => viewer.audiences.includes(a))) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (excluded.some(a => viewer.audiences.includes(a))) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (purpose && !viewer.consents.includes(purpose)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface TreeNode {
|
|
63
|
+
options?: Record<string, unknown>;
|
|
64
|
+
children?: Record<string, TreeNode[]>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The block tree without what this viewer may not see, children included. */
|
|
68
|
+
export function filterBlocksForViewer<T extends TreeNode>(blocks: T[], viewer: Viewer): T[] {
|
|
69
|
+
return blocks
|
|
70
|
+
.filter(block => visibleTo(block.options?.visibility, viewer))
|
|
71
|
+
.map((block) => {
|
|
72
|
+
if (!block.children) {
|
|
73
|
+
return block;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
...block,
|
|
77
|
+
children: Object.fromEntries(
|
|
78
|
+
Object.entries(block.children).map(([field, list]) => [field, filterBlocksForViewer(list, viewer)]),
|
|
79
|
+
),
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The purposes a consent state allows, as the codes the pages app is given. */
|
|
85
|
+
export function grantedPurposes(purposes: Record<string, string> | undefined | null): string[] {
|
|
86
|
+
return codeList(Object.entries(purposes ?? {})
|
|
87
|
+
.filter(([, decision]) => decision === "granted")
|
|
88
|
+
.map(([code]) => code)).sort();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type PopupTrigger = "exit_intent" | "delay_seconds" | "scroll_percent";
|
|
92
|
+
export type PopupFrequency = "once_per_session" | "once_per_day" | "every_page";
|
|
93
|
+
|
|
94
|
+
/** Whether a pop-up with this frequency may open again, given when it last opened. */
|
|
95
|
+
export function popupMayOpen(
|
|
96
|
+
frequency: PopupFrequency,
|
|
97
|
+
lastShown: { session: boolean; at: number | null },
|
|
98
|
+
now: number,
|
|
99
|
+
): boolean {
|
|
100
|
+
if (frequency === "every_page") {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
if (frequency === "once_per_session") {
|
|
104
|
+
return !lastShown.session;
|
|
105
|
+
}
|
|
106
|
+
return lastShown.at === null || now - lastShown.at >= 24 * 60 * 60 * 1000;
|
|
107
|
+
}
|
|
@@ -270,7 +270,7 @@
|
|
|
270
270
|
"orderTemplates": "Bestellvorlagen",
|
|
271
271
|
"projects": "Projekte",
|
|
272
272
|
"devices": "Geräte",
|
|
273
|
-
"points": "
|
|
273
|
+
"points": "Treueprogramm",
|
|
274
274
|
"configurations": "Konfigurationen",
|
|
275
275
|
"inquiries": "Anfragen",
|
|
276
276
|
"quotes": "Angebote",
|
|
@@ -339,7 +339,8 @@
|
|
|
339
339
|
"organization": { "description": "Ihre Organisation verwalten" },
|
|
340
340
|
"team": { "description": "Zugänge und Rollen" },
|
|
341
341
|
"preferences": { "description": "Vorgaben für Ihre Bestellungen" },
|
|
342
|
-
"addresses": { "description": "Liefer- und Rechnungsadressen" }
|
|
342
|
+
"addresses": { "description": "Liefer- und Rechnungsadressen" },
|
|
343
|
+
"points": { "description": "Stufe, Vorteile und Bonus" }
|
|
343
344
|
},
|
|
344
345
|
"comingSoon": {
|
|
345
346
|
"title": "In Entwicklung",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"marketing": {
|
|
3
|
+
"link": {
|
|
4
|
+
"unknownTitle": "Dieser Link funktioniert nicht",
|
|
5
|
+
"unknownText": "Wir kennen diesen Link nicht. Prüfen Sie, ob er vollständig kopiert wurde, oder nehmen Sie den Link aus der neuesten E-Mail.",
|
|
6
|
+
"expiredTitle": "Dieser Link ist abgelaufen",
|
|
7
|
+
"errorTitle": "Das hat nicht geklappt",
|
|
8
|
+
"errorText": "Bitte versuchen Sie es in ein paar Minuten noch einmal.",
|
|
9
|
+
"toShop": "Zum Shop"
|
|
10
|
+
},
|
|
11
|
+
"confirm": {
|
|
12
|
+
"title": "Anmeldung bestätigen",
|
|
13
|
+
"working": "Wir bestätigen Ihre Anmeldung …",
|
|
14
|
+
"doneTitle": "Anmeldung bestätigt",
|
|
15
|
+
"doneText": "Danke. Ab jetzt erhalten Sie unsere E-Mails. Abmelden können Sie sich jederzeit über den Link in jeder E-Mail.",
|
|
16
|
+
"alreadyText": "Diese Anmeldung war schon bestätigt. Sie müssen nichts weiter tun.",
|
|
17
|
+
"expiredText": "Bestätigungslinks gelten nur einige Tage. Melden Sie sich bitte noch einmal an, dann schicken wir Ihnen einen neuen."
|
|
18
|
+
},
|
|
19
|
+
"preferences": {
|
|
20
|
+
"title": "E-Mail-Einstellungen",
|
|
21
|
+
"intro": "Hier legen Sie fest, welche E-Mails wir an {address} schicken.",
|
|
22
|
+
"save": "Einstellungen speichern",
|
|
23
|
+
"saved": "Ihre Einstellungen sind gespeichert.",
|
|
24
|
+
"requested": "Für {types} schicken wir Ihnen eine E-Mail. Erst wenn Sie den Link darin bestätigen, ist die Anmeldung aktiv.",
|
|
25
|
+
"unsubscribeAll": "Von allen E-Mails abmelden",
|
|
26
|
+
"unsubscribedAll": "Sie sind von allen E-Mails abgemeldet. Sie erhalten nur noch Nachrichten zu Ihren Bestellungen.",
|
|
27
|
+
"empty": "Für diese Adresse gibt es keine E-Mails, die Sie wählen können.",
|
|
28
|
+
"expiredText": "Nehmen Sie den Link aus der neuesten E-Mail, die Sie von uns bekommen haben."
|
|
29
|
+
},
|
|
30
|
+
"review": {
|
|
31
|
+
"title": "Ihre Bewertung",
|
|
32
|
+
"intro": "Wie zufrieden sind Sie mit den Artikeln aus Bestellung {order}? Bewerten Sie so viele, wie Sie möchten.",
|
|
33
|
+
"introNoOrder": "Wie zufrieden sind Sie mit Ihren Artikeln? Bewerten Sie so viele, wie Sie möchten.",
|
|
34
|
+
"rating": "Bewertung für {name}",
|
|
35
|
+
"star": "{count} von 5 Sternen",
|
|
36
|
+
"titleField": "Überschrift (optional)",
|
|
37
|
+
"bodyField": "Ihre Erfahrung (optional)",
|
|
38
|
+
"reviewed": "Schon bewertet",
|
|
39
|
+
"submit": "Bewertungen senden",
|
|
40
|
+
"nothingRated": "Wählen Sie für mindestens einen Artikel eine Sternebewertung.",
|
|
41
|
+
"doneTitle": "Danke für Ihre Bewertung",
|
|
42
|
+
"doneText": "Wir prüfen jede Bewertung, bevor sie im Shop erscheint.",
|
|
43
|
+
"partlyRejected": "{count} Bewertung(en) konnten wir nicht annehmen, zum Beispiel weil der Artikel schon bewertet war.",
|
|
44
|
+
"allDone": "Sie haben alle Artikel dieser Bestellung bewertet. Danke!",
|
|
45
|
+
"expiredText": "Bewertungslinks gelten nur eine Zeit lang. Sie können den Artikel weiterhin auf seiner Produktseite finden."
|
|
46
|
+
},
|
|
47
|
+
"loyalty": {
|
|
48
|
+
"title": "Treueprogramm",
|
|
49
|
+
"description": "Ihre Stufe, Ihre Vorteile und wie weit Sie in diesem Jahr sind.",
|
|
50
|
+
"none": "Sie nehmen an keinem Treueprogramm teil.",
|
|
51
|
+
"error": "Ihr Treueprogramm lässt sich gerade nicht laden.",
|
|
52
|
+
"tier": "Ihre Stufe",
|
|
53
|
+
"perks": "Ihre Vorteile",
|
|
54
|
+
"points": "Punktestand",
|
|
55
|
+
"pointsValue": "{points} Punkte",
|
|
56
|
+
"progressTitle": "Bonus {period}",
|
|
57
|
+
"turnoverYtd": "Umsatz bisher",
|
|
58
|
+
"projected": "Hochrechnung zum Jahresende",
|
|
59
|
+
"bonusNow": "Bonus nach heutigem Stand",
|
|
60
|
+
"expectedBonus": "Erwarteter Bonus",
|
|
61
|
+
"nextTier": "Noch {gap} bis {tier} ({percent} % Bonus).",
|
|
62
|
+
"topTier": "Sie haben die höchste Stufe erreicht.",
|
|
63
|
+
"stage": "{tier}: ab {threshold}, {percent} % Bonus",
|
|
64
|
+
"reached": "erreicht",
|
|
65
|
+
"current": "aktuell",
|
|
66
|
+
"rules": "Der Bonus gilt für den gesamten Jahresumsatz in der erreichten Stufe, nicht gestaffelt. Ausgezahlt wird nach Abschluss des Geschäftsjahres.",
|
|
67
|
+
"rulesOverdue": "Voraussetzung ist, dass alle fälligen Rechnungen bezahlt sind.",
|
|
68
|
+
"perkHint": "Ihr Vorteil als {tier}:"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -270,7 +270,7 @@
|
|
|
270
270
|
"orderTemplates": "Order templates",
|
|
271
271
|
"projects": "Projects",
|
|
272
272
|
"devices": "Devices",
|
|
273
|
-
"points": "
|
|
273
|
+
"points": "Loyalty programme",
|
|
274
274
|
"configurations": "Configurations",
|
|
275
275
|
"inquiries": "Inquiries",
|
|
276
276
|
"quotes": "Quotes",
|
|
@@ -339,7 +339,8 @@
|
|
|
339
339
|
"organization": { "description": "Manage your organization" },
|
|
340
340
|
"team": { "description": "Access and roles" },
|
|
341
341
|
"preferences": { "description": "Defaults for your orders" },
|
|
342
|
-
"addresses": { "description": "Delivery and billing addresses" }
|
|
342
|
+
"addresses": { "description": "Delivery and billing addresses" },
|
|
343
|
+
"points": { "description": "Tier, benefits and bonus" }
|
|
343
344
|
},
|
|
344
345
|
"comingSoon": {
|
|
345
346
|
"title": "In development",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"marketing": {
|
|
3
|
+
"link": {
|
|
4
|
+
"unknownTitle": "This link does not work",
|
|
5
|
+
"unknownText": "We do not know this link. Check that it was copied in full, or use the link from the latest email.",
|
|
6
|
+
"expiredTitle": "This link has expired",
|
|
7
|
+
"errorTitle": "That did not work",
|
|
8
|
+
"errorText": "Please try again in a few minutes.",
|
|
9
|
+
"toShop": "Back to the shop"
|
|
10
|
+
},
|
|
11
|
+
"confirm": {
|
|
12
|
+
"title": "Confirm your sign-up",
|
|
13
|
+
"working": "Confirming your sign-up …",
|
|
14
|
+
"doneTitle": "Sign-up confirmed",
|
|
15
|
+
"doneText": "Thank you. From now on you will receive our emails. You can unsubscribe at any time with the link in every email.",
|
|
16
|
+
"alreadyText": "This sign-up was already confirmed. There is nothing else to do.",
|
|
17
|
+
"expiredText": "Confirmation links are only valid for a few days. Please sign up again and we will send you a new one."
|
|
18
|
+
},
|
|
19
|
+
"preferences": {
|
|
20
|
+
"title": "Email settings",
|
|
21
|
+
"intro": "Choose which emails we send to {address}.",
|
|
22
|
+
"save": "Save settings",
|
|
23
|
+
"saved": "Your settings are saved.",
|
|
24
|
+
"requested": "We will send you an email for {types}. The sign-up is active once you confirm the link in it.",
|
|
25
|
+
"unsubscribeAll": "Unsubscribe from all emails",
|
|
26
|
+
"unsubscribedAll": "You are unsubscribed from all emails. You will only receive messages about your orders.",
|
|
27
|
+
"empty": "There are no emails to choose for this address.",
|
|
28
|
+
"expiredText": "Use the link from the latest email you received from us."
|
|
29
|
+
},
|
|
30
|
+
"review": {
|
|
31
|
+
"title": "Your review",
|
|
32
|
+
"intro": "How happy are you with the articles from order {order}? Rate as many as you like.",
|
|
33
|
+
"introNoOrder": "How happy are you with your articles? Rate as many as you like.",
|
|
34
|
+
"rating": "Rating for {name}",
|
|
35
|
+
"star": "{count} of 5 stars",
|
|
36
|
+
"titleField": "Headline (optional)",
|
|
37
|
+
"bodyField": "Your experience (optional)",
|
|
38
|
+
"reviewed": "Already reviewed",
|
|
39
|
+
"submit": "Send reviews",
|
|
40
|
+
"nothingRated": "Choose a star rating for at least one article.",
|
|
41
|
+
"doneTitle": "Thank you for your review",
|
|
42
|
+
"doneText": "We check every review before it appears in the shop.",
|
|
43
|
+
"partlyRejected": "We could not accept {count} review(s), for example because the article was already reviewed.",
|
|
44
|
+
"allDone": "You have reviewed every article of this order. Thank you!",
|
|
45
|
+
"expiredText": "Review links are only valid for a while. You can still find the article on its product page."
|
|
46
|
+
},
|
|
47
|
+
"loyalty": {
|
|
48
|
+
"title": "Loyalty programme",
|
|
49
|
+
"description": "Your tier, your benefits and how far you are this year.",
|
|
50
|
+
"none": "You are not part of a loyalty programme.",
|
|
51
|
+
"error": "Your loyalty programme cannot be loaded right now.",
|
|
52
|
+
"tier": "Your tier",
|
|
53
|
+
"perks": "Your benefits",
|
|
54
|
+
"points": "Points balance",
|
|
55
|
+
"pointsValue": "{points} points",
|
|
56
|
+
"progressTitle": "Bonus {period}",
|
|
57
|
+
"turnoverYtd": "Turnover so far",
|
|
58
|
+
"projected": "Projection to year end",
|
|
59
|
+
"bonusNow": "Bonus as of today",
|
|
60
|
+
"expectedBonus": "Expected bonus",
|
|
61
|
+
"nextTier": "{gap} to go until {tier} ({percent} % bonus).",
|
|
62
|
+
"topTier": "You have reached the highest tier.",
|
|
63
|
+
"stage": "{tier}: from {threshold}, {percent} % bonus",
|
|
64
|
+
"reached": "reached",
|
|
65
|
+
"current": "current",
|
|
66
|
+
"rules": "The bonus applies to the whole year's turnover at the tier reached, not stepwise. It is paid out after the fiscal year closes.",
|
|
67
|
+
"rulesOverdue": "All due invoices must be paid.",
|
|
68
|
+
"perkHint": "Your benefit as {tier}:"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CampaignTouch } from "../../interfaces/marketing";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Onsite impressions and clicks of a campaign's pop-up (RAD-293), counted in
|
|
5
|
+
* the campaigns app. The browser only sends them once the visitor allowed the
|
|
6
|
+
* statistics purpose; the contact and the market are added here, from the
|
|
7
|
+
* session, never taken from the browser.
|
|
8
|
+
*/
|
|
9
|
+
export default defineEventHandler(async (event) => {
|
|
10
|
+
const body = await readBody<{ touches?: unknown }>(event).catch(() => null);
|
|
11
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12
|
+
const touches: CampaignTouch[] = Array.isArray(body?.touches)
|
|
13
|
+
? (body.touches as Record<string, unknown>[])
|
|
14
|
+
.filter(touch => touch && typeof touch.campaign_id === "string" && UUID.test(touch.campaign_id)
|
|
15
|
+
&& (touch.kind === "onsite_impression" || touch.kind === "onsite_click"))
|
|
16
|
+
.slice(0, 50)
|
|
17
|
+
.map(touch => ({
|
|
18
|
+
campaign_id: String(touch.campaign_id),
|
|
19
|
+
kind: touch.kind as CampaignTouch["kind"],
|
|
20
|
+
...(typeof touch.ref === "string" ? { ref: touch.ref.slice(0, 128) } : {}),
|
|
21
|
+
...(typeof touch.key === "string" ? { key: touch.key.slice(0, 200) } : {}),
|
|
22
|
+
}))
|
|
23
|
+
: [];
|
|
24
|
+
if (!touches.length) {
|
|
25
|
+
return { recorded: 0 };
|
|
26
|
+
}
|
|
27
|
+
const contactId = sessionOrderRefs(event).contact_id;
|
|
28
|
+
const market = resolveSelectedMarket(event);
|
|
29
|
+
const sessionKey = getOrCreateCartSessionId(event);
|
|
30
|
+
try {
|
|
31
|
+
await getMarketingService(event).recordTouches(event, touches.map(touch => ({
|
|
32
|
+
...touch,
|
|
33
|
+
...(contactId ? { contact_id: contactId } : { session_key: sessionKey }),
|
|
34
|
+
...(market ? { market } : {}),
|
|
35
|
+
})));
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
// A count that did not arrive is not the visitor's problem.
|
|
39
|
+
getLogService().warn("campaign touches failed", apiErrorContext(err));
|
|
40
|
+
}
|
|
41
|
+
return { recorded: touches.length };
|
|
42
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { sanitizeAttribution } from "../../../app/shared/campaignAttribution";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Where the visit came from, onto the current cart (RAD-293): the carts app
|
|
5
|
+
* keeps it until the cart is ordered, and an abandoned cart's journey reads
|
|
6
|
+
* it. The browser sends it on landing, on every further campaign touch and
|
|
7
|
+
* when the first article goes in; `null` takes it off again once the visitor
|
|
8
|
+
* withdrew the consent it rested on.
|
|
9
|
+
*
|
|
10
|
+
* Best effort by design: no cart yet, the demo cart, or a carts app that
|
|
11
|
+
* refuses the field answer `{ stored: false }` and the visit goes on. Where
|
|
12
|
+
* the visit came from is never a reason to fail a page.
|
|
13
|
+
*/
|
|
14
|
+
export default defineEventHandler(async (event) => {
|
|
15
|
+
const body = await readBody<{ attribution?: unknown }>(event).catch(() => null);
|
|
16
|
+
const attribution = body?.attribution === null ? null : sanitizeAttribution(body?.attribution);
|
|
17
|
+
if (attribution === null && body?.attribution !== null) {
|
|
18
|
+
return { stored: false };
|
|
19
|
+
}
|
|
20
|
+
const manager = getCartManager(event);
|
|
21
|
+
if (!manager) {
|
|
22
|
+
return { stored: false };
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
return { stored: await manager.setActiveCartAttribution(event, attribution) };
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
getLogService().warn("cart attribution not stored", apiErrorContext(err));
|
|
29
|
+
return { stored: false };
|
|
30
|
+
}
|
|
31
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LoyaltyAccount } from "../../interfaces/marketing";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The signed-in buyer's loyalty membership (RAD-293): the programme and tier,
|
|
5
|
+
* the points balance, and — for a yearly turnover bonus like eltric "Premium"
|
|
6
|
+
* — how far the company is this year. A company agreement is the
|
|
7
|
+
* organisation's, so the buyer's organisation goes along.
|
|
8
|
+
*
|
|
9
|
+
* Nobody signed in is a 401; a buyer in no programme, or a shop without the
|
|
10
|
+
* loyalty app, is `null` — the page then says there is nothing to show.
|
|
11
|
+
*/
|
|
12
|
+
export default defineEventHandler(async (event): Promise<LoyaltyAccount | null> => {
|
|
13
|
+
const user = await getAuthService(event).me(event);
|
|
14
|
+
if (!user) {
|
|
15
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
16
|
+
}
|
|
17
|
+
const refs = sessionOrderRefs(event);
|
|
18
|
+
const contactId = user.contactId ?? refs.contact_id;
|
|
19
|
+
// A demo persona has no contact; the mock answers for it anyway.
|
|
20
|
+
if (!contactId && resolveMarketingServiceKey(event) === "api") {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return await getMarketingService(event).loyaltyAccount(event, {
|
|
24
|
+
contactId: contactId ?? "",
|
|
25
|
+
organizationId: refs.organization_id ?? null,
|
|
26
|
+
});
|
|
27
|
+
});
|