@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.
Files changed (45) hide show
  1. package/app/api/marketing.ts +24 -0
  2. package/app/app.config.ts +22 -0
  3. package/app/components/account/loyalty/AccountLoyalty.vue +205 -0
  4. package/app/components/cart/view/CartSummaryPanel.vue +4 -0
  5. package/app/components/checkout/onepage/CheckoutSummarySection.vue +4 -0
  6. package/app/components/loyalty/hint/LoyaltyPerkHint.vue +28 -0
  7. package/app/components/newsletter/confirm/NewsletterConfirmation.vue +54 -0
  8. package/app/components/newsletter/preferences/NewsletterPreferenceCentre.vue +183 -0
  9. package/app/components/newsletter/state/NewsletterLinkRefusal.vue +45 -0
  10. package/app/components/review/form/ReviewForm.vue +211 -0
  11. package/app/composables/useCampaignAttribution.ts +120 -0
  12. package/app/composables/useCheckoutOnePage.ts +9 -0
  13. package/app/composables/useLoyaltyAccount.ts +79 -0
  14. package/app/composables/useMarketingConsent.ts +49 -0
  15. package/app/config/navigation.ts +1 -1
  16. package/app/config/quickActions.ts +1 -0
  17. package/app/pages/account/points.vue +26 -0
  18. package/app/pages/newsletter/confirm/[token].vue +23 -0
  19. package/app/pages/newsletter/preferences/[token].vue +24 -0
  20. package/app/pages/review/[token].vue +23 -0
  21. package/app/plugins/campaign-attribution.client.ts +47 -0
  22. package/app/shared/campaignAttribution.ts +281 -0
  23. package/app/shared/personalisation.ts +107 -0
  24. package/i18n/locales/de/account.json +3 -2
  25. package/i18n/locales/de/marketing.json +71 -0
  26. package/i18n/locales/en/account.json +3 -2
  27. package/i18n/locales/en/marketing.json +71 -0
  28. package/package.json +1 -1
  29. package/server/api/campaigns/touches.post.ts +42 -0
  30. package/server/api/cart/attribution.put.ts +31 -0
  31. package/server/api/loyalty/account.get.ts +27 -0
  32. package/server/api/newsletter/confirm/[token].post.ts +21 -0
  33. package/server/api/newsletter/preferences/[token].get.ts +14 -0
  34. package/server/api/newsletter/preferences/[token].post.ts +36 -0
  35. package/server/api/orders/index.post.ts +10 -1
  36. package/server/api/reviews/requests/[token].get.ts +14 -0
  37. package/server/api/reviews/submit/[token].post.ts +31 -0
  38. package/server/interfaces/cart.ts +6 -0
  39. package/server/interfaces/marketing.ts +150 -0
  40. package/server/services/ApiCartService.ts +16 -0
  41. package/server/services/ApiMarketingService.ts +292 -0
  42. package/server/services/MockMarketingService.ts +178 -0
  43. package/server/utils/marketingService.ts +63 -0
  44. package/server/utils/orderAttribution.ts +65 -0
  45. package/server/utils/personalisationViewer.ts +28 -0
@@ -0,0 +1,211 @@
1
+ <script setup lang="ts">
2
+ import { linkRefusalOf, marketingApi } from "../../../api/marketing";
3
+ import NewsletterLinkRefusal from "../../newsletter/state/NewsletterLinkRefusal.vue";
4
+
5
+ /**
6
+ * The review form behind a review request link (RAD-293). The buyer rates
7
+ * the products of one order — as many as they like, a star rating each, a
8
+ * headline and a text if they want — and sends them together. A product they
9
+ * already rated is shown as done and cannot be rated twice.
10
+ *
11
+ * Nothing appears in the shop straight away: the merchant moderates.
12
+ */
13
+ const props = defineProps<{ token: string }>();
14
+
15
+ interface ReviewProduct {
16
+ productId: string;
17
+ sku: string | null;
18
+ name: string;
19
+ reviewed: boolean;
20
+ }
21
+
22
+ interface ReviewRequest {
23
+ orderNumber: string | null;
24
+ products: ReviewProduct[];
25
+ }
26
+
27
+ interface Draft {
28
+ rating: number;
29
+ title: string;
30
+ body: string;
31
+ }
32
+
33
+ const { t } = useI18n();
34
+ const { icon } = useIcons();
35
+
36
+ const { data, error, status, refresh } = await useFetch<ReviewRequest>(() => marketingApi.reviewRequest(props.token), {
37
+ key: `review-request:${props.token}`,
38
+ });
39
+
40
+ const drafts = reactive<Record<string, Draft>>({});
41
+ watch(data, (request) => {
42
+ for (const product of request?.products ?? []) {
43
+ drafts[product.productId] ??= { rating: 0, title: "", body: "" };
44
+ }
45
+ }, { immediate: true });
46
+
47
+ const refusal = computed(() => (error.value ? linkRefusalOf(error.value) : null));
48
+ const open = computed(() => (data.value?.products ?? []).filter(product => !product.reviewed));
49
+
50
+ const sending = ref(false);
51
+ const formError = ref<string | null>(null);
52
+ const result = ref<{ accepted: number; rejected: number } | null>(null);
53
+
54
+ async function submit(): Promise<void> {
55
+ const reviews = open.value
56
+ .filter(product => (drafts[product.productId]?.rating ?? 0) > 0)
57
+ .map((product) => {
58
+ const draft = drafts[product.productId]!;
59
+ return {
60
+ product_id: product.productId,
61
+ rating: draft.rating,
62
+ ...(draft.title.trim() ? { title: draft.title.trim() } : {}),
63
+ ...(draft.body.trim() ? { body: draft.body.trim() } : {}),
64
+ };
65
+ });
66
+ if (!reviews.length) {
67
+ formError.value = t("marketing.review.nothingRated");
68
+ return;
69
+ }
70
+ formError.value = null;
71
+ sending.value = true;
72
+ try {
73
+ const answer = await $fetch<{ accepted: string[]; rejected: unknown[] }>(marketingApi.reviewSubmit(props.token), {
74
+ method: "POST",
75
+ body: { reviews },
76
+ });
77
+ result.value = { accepted: answer.accepted.length, rejected: answer.rejected.length };
78
+ await refresh();
79
+ }
80
+ catch (err) {
81
+ const kind = linkRefusalOf(err);
82
+ formError.value = kind === "expired" ? t("marketing.review.expiredText") : t("marketing.link.errorText");
83
+ }
84
+ finally {
85
+ sending.value = false;
86
+ }
87
+ }
88
+ </script>
89
+
90
+ <template>
91
+ <div data-review-form>
92
+ <NewsletterLinkRefusal
93
+ v-if="refusal"
94
+ :refusal="refusal"
95
+ :expired-text="t('marketing.review.expiredText')"
96
+ />
97
+ <USkeleton
98
+ v-else-if="status === 'pending' && !data"
99
+ class="h-40 w-full"
100
+ />
101
+ <template v-else-if="data">
102
+ <UAlert
103
+ v-if="result && result.accepted"
104
+ class="mb-6"
105
+ color="success"
106
+ variant="soft"
107
+ role="status"
108
+ :title="t('marketing.review.doneTitle')"
109
+ :description="t('marketing.review.doneText')"
110
+ />
111
+ <UAlert
112
+ v-if="result && result.rejected"
113
+ class="mb-6"
114
+ color="warning"
115
+ variant="soft"
116
+ :description="t('marketing.review.partlyRejected', { count: result.rejected })"
117
+ />
118
+
119
+ <p
120
+ v-if="!open.length"
121
+ class="text-muted"
122
+ data-review-all-done
123
+ >
124
+ {{ t('marketing.review.allDone') }}
125
+ </p>
126
+ <template v-else>
127
+ <p class="text-muted mb-6">
128
+ {{ data.orderNumber ? t('marketing.review.intro', { order: data.orderNumber }) : t('marketing.review.introNoOrder') }}
129
+ </p>
130
+ <form
131
+ class="space-y-6"
132
+ novalidate
133
+ @submit.prevent="submit"
134
+ >
135
+ <fieldset
136
+ v-for="product in data.products"
137
+ :key="product.productId"
138
+ class="border border-(--ui-border) rounded-lg p-4 space-y-3"
139
+ :disabled="product.reviewed"
140
+ :data-review-product="product.productId"
141
+ >
142
+ <legend class="px-1 font-medium text-highlighted">
143
+ {{ product.name }}
144
+ </legend>
145
+ <p
146
+ v-if="product.reviewed"
147
+ class="text-sm text-success"
148
+ >
149
+ {{ t('marketing.review.reviewed') }}
150
+ </p>
151
+ <template v-else>
152
+ <div
153
+ role="radiogroup"
154
+ class="flex gap-1"
155
+ :aria-label="t('marketing.review.rating', { name: product.name })"
156
+ >
157
+ <button
158
+ v-for="star in 5"
159
+ :key="star"
160
+ type="button"
161
+ role="radio"
162
+ class="p-1 rounded-md focus-visible:outline-2 focus-visible:outline-primary"
163
+ :aria-checked="drafts[product.productId]?.rating === star"
164
+ :aria-label="t('marketing.review.star', { count: star })"
165
+ :data-star="star"
166
+ @click="drafts[product.productId]!.rating = star"
167
+ >
168
+ <UIcon
169
+ :name="icon('star')"
170
+ class="size-6"
171
+ :class="star <= (drafts[product.productId]?.rating ?? 0) ? 'text-primary' : 'text-dimmed'"
172
+ />
173
+ </button>
174
+ </div>
175
+ <UFormField :label="t('marketing.review.titleField')">
176
+ <UInput
177
+ v-model="drafts[product.productId]!.title"
178
+ :maxlength="200"
179
+ class="w-full"
180
+ />
181
+ </UFormField>
182
+ <UFormField :label="t('marketing.review.bodyField')">
183
+ <UTextarea
184
+ v-model="drafts[product.productId]!.body"
185
+ :maxlength="5000"
186
+ :rows="4"
187
+ class="w-full"
188
+ />
189
+ </UFormField>
190
+ </template>
191
+ </fieldset>
192
+
193
+ <p
194
+ v-if="formError"
195
+ class="text-sm text-error"
196
+ role="alert"
197
+ >
198
+ {{ formError }}
199
+ </p>
200
+
201
+ <UButton
202
+ type="submit"
203
+ :loading="sending"
204
+ >
205
+ {{ t('marketing.review.submit') }}
206
+ </UButton>
207
+ </form>
208
+ </template>
209
+ </template>
210
+ </div>
211
+ </template>
@@ -0,0 +1,120 @@
1
+ import type { Attribution, LandingTouch, StoredAttribution } from "../shared/campaignAttribution";
2
+ import {
3
+ ATTRIBUTION_STORAGE_KEY,
4
+ landingTouchOf,
5
+ mergeTouch,
6
+ parseStoredAttribution,
7
+ toAttribution,
8
+ withoutClickId,
9
+ } from "../shared/campaignAttribution";
10
+
11
+ function storage(): Storage | null {
12
+ try {
13
+ return import.meta.client ? window.localStorage : null;
14
+ }
15
+ catch {
16
+ return null;
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Where the visit came from (RAD-293): captured from the address a visitor
22
+ * lands on, kept in the browser, written onto the cart and sent with the
23
+ * order.
24
+ *
25
+ * Nothing is written anywhere before the cookie choice allows it. A campaign
26
+ * address seen before the visitor decided is held in memory only, for the
27
+ * rest of the visit, and kept the moment they allow statistics or marketing.
28
+ * Withdrawing both takes everything off again — the browser's copy and the
29
+ * cart's. The ad click id needs the marketing purpose on its own.
30
+ */
31
+ export function useCampaignAttribution() {
32
+ const consent = useMarketingConsent();
33
+ const pending = useState<LandingTouch | null>("cover:attribution:pending", () => null);
34
+
35
+ function read(): StoredAttribution | null {
36
+ return parseStoredAttribution(storage()?.getItem(ATTRIBUTION_STORAGE_KEY) ?? null, new Date());
37
+ }
38
+
39
+ function write(value: StoredAttribution | null): void {
40
+ try {
41
+ if (value) {
42
+ storage()?.setItem(ATTRIBUTION_STORAGE_KEY, JSON.stringify(value));
43
+ }
44
+ else {
45
+ storage()?.removeItem(ATTRIBUTION_STORAGE_KEY);
46
+ }
47
+ }
48
+ catch {
49
+ // Storage full or blocked: attribution is a nicety, never an error.
50
+ }
51
+ }
52
+
53
+ function allowed(): boolean {
54
+ const c = consent.attributionConsent.value;
55
+ return c.analytics || c.ads;
56
+ }
57
+
58
+ /** The attribution as it stands, or null when there is none or nothing allows it. */
59
+ function current(options: { objectionNoticeShown?: boolean } = {}): Attribution | null {
60
+ if (!allowed()) {
61
+ return null;
62
+ }
63
+ const stored = read();
64
+ return stored ? toAttribution(stored, consent.attributionConsent.value, options) : null;
65
+ }
66
+
67
+ async function syncToCart(): Promise<void> {
68
+ const attribution = current();
69
+ if (!attribution) {
70
+ return;
71
+ }
72
+ await $fetch("/api/cart/attribution", { method: "PUT", body: { attribution } }).catch(() => {});
73
+ }
74
+
75
+ /** Keeps what is pending, if the cookie choice now allows it, and tells the cart. */
76
+ async function flush(): Promise<void> {
77
+ if (!allowed()) {
78
+ return;
79
+ }
80
+ const ads = consent.attributionConsent.value.ads;
81
+ let stored = read();
82
+ if (pending.value) {
83
+ stored = mergeTouch(stored, pending.value, { allowClickId: ads });
84
+ pending.value = null;
85
+ }
86
+ else if (stored && !ads) {
87
+ stored = withoutClickId(stored);
88
+ }
89
+ else if (!stored) {
90
+ return;
91
+ }
92
+ write(stored);
93
+ await syncToCart();
94
+ }
95
+
96
+ /** A page was reached: remember its campaign, if it carries one. */
97
+ async function capture(url: URL, referrer: string | null): Promise<void> {
98
+ const touch = landingTouchOf(url, referrer, new Date());
99
+ if (!touch) {
100
+ return;
101
+ }
102
+ pending.value = touch;
103
+ await flush();
104
+ }
105
+
106
+ /** The cookie choice changed: keep what may be kept, drop what may not. */
107
+ async function consentChanged(): Promise<void> {
108
+ if (allowed()) {
109
+ await flush();
110
+ return;
111
+ }
112
+ const had = read() !== null;
113
+ write(null);
114
+ if (had) {
115
+ await $fetch("/api/cart/attribution", { method: "PUT", body: { attribution: null } }).catch(() => {});
116
+ }
117
+ }
118
+
119
+ return { capture, consentChanged, current, syncToCart };
120
+ }
@@ -59,6 +59,7 @@ export function useCheckoutOnePage() {
59
59
  const cart = useCartStore();
60
60
  const { settings } = useB2BContext();
61
61
  const psp = usePspCheckout();
62
+ const campaignAttribution = useCampaignAttribution();
62
63
  // The server-calculated totals the summary shows (shared state) — read when
63
64
  // an order is placed, so the confirmation can report what was bought.
64
65
  const calculation = useState<CartCalculation | null>("cart-calculation", () => null);
@@ -332,6 +333,14 @@ export function useCheckoutOnePage() {
332
333
  await fetchSessionToken();
333
334
 
334
335
  const payload = buildOrderPayload() as Record<string, unknown>;
336
+ // Where the visit came from, if the cookie choice allows keeping it
337
+ // (RAD-293). The orders app takes it from the order, never from the
338
+ // cart, so it travels here. The objection notice for advertising to
339
+ // existing customers is not shown by this checkout, and is said so.
340
+ const attribution = campaignAttribution.current({ objectionNoticeShown: false });
341
+ if (attribution) {
342
+ payload.attribution = attribution;
343
+ }
335
344
  // PSP card methods (Stripe Elements, …) tokenize client-side; only
336
345
  // the single-use token reaches the BFF (PCI-safe). Self-managed and
337
346
  // redirect methods carry no instrument here.
@@ -0,0 +1,79 @@
1
+ import { marketingApi } from "../api/marketing";
2
+
3
+ type Labels = Record<string, string> | null;
4
+
5
+ export interface LoyaltyAccountView {
6
+ memberships: {
7
+ program: { code: string; labels: Labels; kind: string };
8
+ tier: { code: string; labels: Labels; perks: Labels[] } | null;
9
+ pointsBalance: number | null;
10
+ agreementId: string | null;
11
+ }[];
12
+ progress: {
13
+ period: string | number | null;
14
+ currency: string;
15
+ turnoverYtd: number;
16
+ projectedTurnover: number | null;
17
+ tiers: { code: string; labels: Labels; threshold: number | null; bonusPercent: number; reached: boolean; current: boolean }[];
18
+ nextTier: { code: string; labels: Labels; gap: number; bonusPercent: number } | null;
19
+ bonusNow: number | null;
20
+ expectedBonus: number | null;
21
+ requiresNoOverdue: boolean;
22
+ } | null;
23
+ }
24
+
25
+ /**
26
+ * The signed-in buyer's loyalty membership (RAD-293), fetched once per page
27
+ * and shared by the account page and the perk hint in cart and checkout.
28
+ * Guests ask nothing: a membership is a signed-in buyer's.
29
+ */
30
+ export function useLoyaltyAccount() {
31
+ const auth = useAuthStore();
32
+ const { locale } = useI18n();
33
+ const signedIn = computed(() => Boolean(auth.user));
34
+
35
+ const request = useFetch<LoyaltyAccountView | null>(marketingApi.loyaltyAccount(), {
36
+ key: "loyalty-account",
37
+ immediate: signedIn.value,
38
+ watch: false,
39
+ default: () => null,
40
+ // Anything but the expected shape — an HTML error page, a proxy's
41
+ // answer — reads as no membership rather than breaking the cart.
42
+ transform: (value: unknown) =>
43
+ value && typeof value === "object" && Array.isArray((value as LoyaltyAccountView).memberships)
44
+ ? value as LoyaltyAccountView
45
+ : null,
46
+ });
47
+
48
+ // Signing in asks; signing out forgets — a guest never asks at all.
49
+ watch(signedIn, (now) => {
50
+ if (now) {
51
+ void request.refresh();
52
+ }
53
+ else {
54
+ request.data.value = null;
55
+ }
56
+ });
57
+
58
+ /** A label in the shop's language, else German, else whatever there is. */
59
+ function label(labels: Labels | undefined, fallback = ""): string {
60
+ if (!labels) {
61
+ return fallback;
62
+ }
63
+ return labels[locale.value] ?? labels.de ?? Object.values(labels)[0] ?? fallback;
64
+ }
65
+
66
+ /** The tier whose perks a buyer has, and the perks in their language. */
67
+ const perks = computed(() => {
68
+ const membership = request.data.value?.memberships.find(m => m.tier?.perks.length);
69
+ if (!membership?.tier) {
70
+ return null;
71
+ }
72
+ return {
73
+ tier: label(membership.tier.labels, membership.tier.code),
74
+ items: membership.tier.perks.map(perk => label(perk)).filter(Boolean),
75
+ };
76
+ });
77
+
78
+ return { ...request, signedIn, label, perks };
79
+ }
@@ -0,0 +1,49 @@
1
+ import type { AttributionConsent } from "../shared/campaignAttribution";
2
+ import { grantedPurposes } from "../shared/personalisation";
3
+
4
+ /** The marketing functions that rest on the visitor's cookie choice. */
5
+ export type MarketingFunction = "analytics" | "ads" | "personalisation" | "touches";
6
+
7
+ const DEFAULT_PURPOSES: Record<MarketingFunction, string> = {
8
+ analytics: "statistics",
9
+ ads: "marketing",
10
+ personalisation: "marketing",
11
+ touches: "statistics",
12
+ };
13
+
14
+ /**
15
+ * What the visitor's cookie choice allows the marketing functions (RAD-293),
16
+ * read from the Consent Manager. The purpose each function rests on is the
17
+ * storefront's `marketing.purposes` app config; a function whose purpose is
18
+ * not granted does nothing.
19
+ *
20
+ * Without a published policy nothing is granted, so a shop that has not set
21
+ * up its cookie choice tracks nothing — the Consent Manager fails closed and
22
+ * this follows it.
23
+ */
24
+ export function useMarketingConsent() {
25
+ const consents = useConsents();
26
+ const appConfig = useAppConfig() as { marketing?: { purposes?: Partial<Record<MarketingFunction, string>> } };
27
+ const purposeOf = (fn: MarketingFunction): string =>
28
+ appConfig.marketing?.purposes?.[fn] ?? DEFAULT_PURPOSES[fn];
29
+
30
+ /** Every purpose the visitor allowed, as policy codes, sorted. */
31
+ const granted = computed<string[]>(() => grantedPurposes(consents.state.value?.purposes));
32
+
33
+ function allows(fn: MarketingFunction): boolean {
34
+ return granted.value.includes(purposeOf(fn));
35
+ }
36
+
37
+ /** The consent half of a cart's or an order's attribution. */
38
+ const attributionConsent = computed<AttributionConsent>(() => {
39
+ const version = consents.policy.value?.version?.number;
40
+ return {
41
+ ads: allows("ads"),
42
+ analytics: allows("analytics"),
43
+ policy_version: typeof version === "number" ? String(version) : null,
44
+ purposes: granted.value,
45
+ };
46
+ });
47
+
48
+ return { granted, allows, attributionConsent, onChange: consents.onChange };
49
+ }
@@ -175,7 +175,7 @@ export const accountNavigation: AccountNavGroup[] = [
175
175
  { labelKey: "account.nav.orderLists", icon: "order-list", to: "/account/order-lists", implemented: true },
176
176
  { labelKey: "account.nav.projects", icon: "folder", to: "/account/projects" },
177
177
  { labelKey: "account.nav.devices", icon: "smartphone", to: "/account/devices" },
178
- { labelKey: "account.nav.points", icon: "star", to: "/account/points" },
178
+ { labelKey: "account.nav.points", icon: "star", to: "/account/points", implemented: true },
179
179
  { labelKey: "account.nav.configurations", icon: "settings", to: "/account/configurations" },
180
180
  ],
181
181
  },
@@ -50,6 +50,7 @@ const QUICK_ACTION_ORDER: readonly string[] = [
50
50
  "team",
51
51
  "preferences",
52
52
  "addresses",
53
+ "points",
53
54
  ];
54
55
 
55
56
  /** The default selection: the four ordering shortcuts, in the order above. */
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import AccountLoyalty from "../../components/account/loyalty/AccountLoyalty.vue";
3
+
4
+ /**
5
+ * The loyalty programme in the account (RAD-293). Shipped by the layer, so
6
+ * every storefront's account has it without a page of its own; the account
7
+ * navigation has pointed here since the roadmap entry "Punkte".
8
+ */
9
+ const { t } = useI18n();
10
+
11
+ useHead({ title: () => t("marketing.loyalty.title") });
12
+ </script>
13
+
14
+ <template>
15
+ <AccountShell>
16
+ <div class="mb-6">
17
+ <h1 class="text-2xl font-semibold text-highlighted">
18
+ {{ t('marketing.loyalty.title') }}
19
+ </h1>
20
+ <p class="text-sm text-muted mt-1">
21
+ {{ t('marketing.loyalty.description') }}
22
+ </p>
23
+ </div>
24
+ <AccountLoyalty />
25
+ </AccountShell>
26
+ </template>
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ import NewsletterConfirmation from "../../../components/newsletter/confirm/NewsletterConfirmation.vue";
3
+
4
+ /**
5
+ * Where the double opt-in mail's link lands (RAD-293). The tenant enters
6
+ * this address, with `{token}`, as marketing-consents' market setting
7
+ * `confirmation_page_url`. Shipped by the layer, so every storefront has it.
8
+ */
9
+ const { t } = useI18n();
10
+ const route = useRoute();
11
+ const token = computed(() => String(route.params.token ?? ""));
12
+
13
+ useHead({ title: () => t("marketing.confirm.title"), meta: [{ name: "robots", content: "noindex" }] });
14
+ </script>
15
+
16
+ <template>
17
+ <UContainer class="max-w-xl py-10 lg:py-14">
18
+ <h1 class="text-2xl font-semibold text-highlighted mb-6">
19
+ {{ t('marketing.confirm.title') }}
20
+ </h1>
21
+ <NewsletterConfirmation :token="token" />
22
+ </UContainer>
23
+ </template>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ import NewsletterPreferenceCentre from "../../../components/newsletter/preferences/NewsletterPreferenceCentre.vue";
3
+
4
+ /**
5
+ * The preference centre (RAD-293) behind the link in every mail's footer.
6
+ * The tenant enters this address, with `{token}`, as marketing-consents'
7
+ * market setting `preference_centre_url`. Open to everybody holding the link:
8
+ * a recipient needs no account to change what they receive.
9
+ */
10
+ const { t } = useI18n();
11
+ const route = useRoute();
12
+ const token = computed(() => String(route.params.token ?? ""));
13
+
14
+ useHead({ title: () => t("marketing.preferences.title"), meta: [{ name: "robots", content: "noindex" }] });
15
+ </script>
16
+
17
+ <template>
18
+ <UContainer class="max-w-xl py-10 lg:py-14">
19
+ <h1 class="text-2xl font-semibold text-highlighted mb-2">
20
+ {{ t('marketing.preferences.title') }}
21
+ </h1>
22
+ <NewsletterPreferenceCentre :token="token" />
23
+ </UContainer>
24
+ </template>
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ import ReviewForm from "../../components/review/form/ReviewForm.vue";
3
+
4
+ /**
5
+ * The review form behind a review request link (RAD-293). The tenant enters
6
+ * this address, with `{token}`, as the reviews app's market setting
7
+ * `review_form_url`; until then the reviews app issues no link at all.
8
+ */
9
+ const { t } = useI18n();
10
+ const route = useRoute();
11
+ const token = computed(() => String(route.params.token ?? ""));
12
+
13
+ useHead({ title: () => t("marketing.review.title"), meta: [{ name: "robots", content: "noindex" }] });
14
+ </script>
15
+
16
+ <template>
17
+ <UContainer class="max-w-2xl py-10 lg:py-14">
18
+ <h1 class="text-2xl font-semibold text-highlighted mb-2">
19
+ {{ t('marketing.review.title') }}
20
+ </h1>
21
+ <ReviewForm :token="token" />
22
+ </UContainer>
23
+ </template>
@@ -0,0 +1,47 @@
1
+ import { isEditorContext } from "../shared/themeEvents";
2
+
3
+ /**
4
+ * Captures where a visit came from (RAD-293): on the first page and on every
5
+ * later one that carries a campaign, whenever the cookie choice changes, and
6
+ * once more when the first article goes into a cart that did not exist when
7
+ * the visitor landed. The editor and previews are no visit.
8
+ */
9
+ export default defineNuxtPlugin({
10
+ name: "cover:campaign-attribution",
11
+ setup(nuxtApp) {
12
+ const route = useRoute();
13
+ if (isEditorContext({ path: route.path, host: window.location.host, query: route.query })) {
14
+ return;
15
+ }
16
+ const attribution = useCampaignAttribution();
17
+ const router = useRouter();
18
+ const cart = useCartStore();
19
+
20
+ let first = true;
21
+ const run = (): void => {
22
+ // Only the landing has a referrer of its own; a later page was
23
+ // reached from this shop.
24
+ const referrer = first ? document.referrer || null : null;
25
+ first = false;
26
+ void attribution.capture(new URL(window.location.href), referrer);
27
+ };
28
+
29
+ nuxtApp.hook("app:mounted", run);
30
+ router.afterEach((to, from) => {
31
+ if (!first && to.fullPath !== from.fullPath) {
32
+ run();
33
+ }
34
+ });
35
+
36
+ const provider = nuxtApp.$consentProvider as { onChange?: (cb: () => void) => () => void } | undefined;
37
+ provider?.onChange?.(() => {
38
+ void attribution.consentChanged();
39
+ });
40
+
41
+ watch(() => cart.items.length, (now, before) => {
42
+ if (before === 0 && now > 0) {
43
+ void attribution.syncToCart();
44
+ }
45
+ });
46
+ },
47
+ });