@eldrajs/theme-nuxt 0.3.3 → 0.4.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/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ Release-please writes the generated notes from commit messages and does not repl
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ - **Campaign landings are captured (WS-546).** A client plugin calls `@eldrajs/sdk`'s
9
+ `captureCampaignAttribution` on the first page and after every navigation, so a theme's cart adds
10
+ carry the campaign a visitor came from (`utm_*` tags only, one `localStorage` key, 30 days). New
11
+ option `campaignAttribution: false` turns it off.
12
+
13
+ - **The site profile carries the registered company.** `readSiteProfile`, `resolveSiteProfile` and
14
+ `useSiteProfile()` gain `legal` (`{name, kennitala, streetAddress, postalCode, city,
15
+ countryCode}` or `null`), from `GET /site/v1/site-profile` since public contract 5.1.0; a
16
+ platform before that reads as `null`. The starter writes it on the home `Organization` as
17
+ `legalName`, `taxID` and `address`.
18
+
8
19
  - **Prerender reads shared lists once per build (WS-406).** `nuxi generate` created a client per
9
20
  route, so the page list, the route-template list and the category list behind link resolution
10
21
  were read once per route (the category list about 136 times in one staging build). During a
package/dist/module.d.mts CHANGED
@@ -95,6 +95,8 @@ interface ModuleOptions {
95
95
  * proxy on the site's own domain. No cookie or storage identifier is written.
96
96
  */
97
97
  analytics?: AnalyticsOption;
98
+ /** Keeps a landing's campaign `utm_*` tags for cart adds once the visitor agrees (docs/themes.md, Campaign attribution); `false` leaves it out. */
99
+ campaignAttribution?: boolean;
98
100
  }
99
101
  declare const eldraModule: NuxtModule<ModuleOptions>;
100
102
 
package/dist/module.d.ts CHANGED
@@ -95,6 +95,8 @@ interface ModuleOptions {
95
95
  * proxy on the site's own domain. No cookie or storage identifier is written.
96
96
  */
97
97
  analytics?: AnalyticsOption;
98
+ /** Keeps a landing's campaign `utm_*` tags for cart adds once the visitor agrees (docs/themes.md, Campaign attribution); `false` leaves it out. */
99
+ campaignAttribution?: boolean;
98
100
  }
99
101
  declare const eldraModule: NuxtModule<ModuleOptions>;
100
102
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.13.0"
6
6
  },
7
- "version": "0.3.3",
7
+ "version": "0.4.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -128,6 +128,9 @@ const eldraModule = defineNuxtModule({
128
128
  const buildToken = (process.env.ELDRA_BUILD_TOKEN ?? "").trim();
129
129
  addPlugin(resolver.resolve("./runtime/plugin"));
130
130
  addPlugin(resolver.resolve("./runtime/analyticsPlugin"));
131
+ if (options.campaignAttribution !== false) {
132
+ addPlugin({ src: resolver.resolve("./runtime/attributionPlugin"), mode: "client" });
133
+ }
131
134
  addImports([
132
135
  {
133
136
  name: "useEldraBuildToken",
@@ -0,0 +1,9 @@
1
+ declare global {
2
+ interface Window {
3
+ /** The visitor's answer from the site's consent tool; the kit keeps campaign tags only while it is `true`. */
4
+ eldraCampaignAttributionConsent?: boolean;
5
+ }
6
+ }
7
+ /** Notes the campaign a visitor landed from and keeps it, for `@eldrajs/sdk`'s `cart.addItem`, once they agree. */
8
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
9
+ export default _default;
@@ -0,0 +1,22 @@
1
+ import {
2
+ captureCampaignAttribution,
3
+ grantCampaignAttributionConsent,
4
+ withdrawCampaignAttributionConsent
5
+ } from "@eldrajs/sdk";
6
+ import { defineNuxtPlugin, useRouter } from "nuxt/app";
7
+ const CONSENT_EVENT = "eldra:campaign-attribution-consent";
8
+ function applyConsent() {
9
+ if (window.eldraCampaignAttributionConsent === true) grantCampaignAttributionConsent();
10
+ else if (window.eldraCampaignAttributionConsent === false) withdrawCampaignAttributionConsent();
11
+ }
12
+ export default defineNuxtPlugin({
13
+ name: "eldra-campaign-attribution",
14
+ setup() {
15
+ applyConsent();
16
+ window.addEventListener(CONSENT_EVENT, applyConsent);
17
+ captureCampaignAttribution(window.location.href);
18
+ useRouter().afterEach((to, _from, failure) => {
19
+ if (!failure) captureCampaignAttribution(to.fullPath);
20
+ });
21
+ }
22
+ });
@@ -25,7 +25,7 @@ export declare function useStructuredData(entries: MaybeRefOrGetter<readonly Str
25
25
  enabled?: MaybeRefOrGetter<boolean>;
26
26
  }): void;
27
27
  /**
28
- * The shop's profile for an `Organization` node (name, logo, social links, contact), with the
28
+ * The shop's profile for an `Organization` node (name, logo, social links, contact, legal details), with the
29
29
  * site name and the site icon filling what the merchant left unset, plus the site's origin.
30
30
  * `siteUrl` is `''` when the build does not know it; the page then has no absolute URL to write,
31
31
  * and should write no node that needs one.
@@ -50,6 +50,7 @@ export function useSiteProfile() {
50
50
  email: resolved?.contact?.email || null,
51
51
  telephone: resolved?.contact?.telephone || null
52
52
  },
53
+ legal: resolved?.legal ?? null,
53
54
  siteUrl: seo.siteUrl ?? ""
54
55
  };
55
56
  }
@@ -16,6 +16,19 @@ export interface SiteProfileSetting {
16
16
  email: string | null;
17
17
  telephone: string | null;
18
18
  };
19
+ /** The registered company, or `null` for a sole trader, no legal details, or a platform before 5.1.0. */
20
+ legal: SiteProfileLegal | null;
21
+ }
22
+ /** The registered company behind the site, from the organisation's legal details in Studio. */
23
+ export interface SiteProfileLegal {
24
+ name: string | null;
25
+ /** As people write it, `dddddd-dddd`. */
26
+ kennitala: string;
27
+ streetAddress: string | null;
28
+ postalCode: string | null;
29
+ city: string | null;
30
+ /** ISO 3166-1 alpha-2. */
31
+ countryCode: string | null;
19
32
  }
20
33
  /** What a page's `Organization` is written from: gaps already filled, `name` never empty. */
21
34
  export interface ResolvedSiteProfile {
@@ -26,6 +39,7 @@ export interface ResolvedSiteProfile {
26
39
  email: string | null;
27
40
  telephone: string | null;
28
41
  };
42
+ legal: SiteProfileLegal | null;
29
43
  }
30
44
  /**
31
45
  * The slice of an `@eldrajs/sdk` client this read needs — a whole `EldraClient` satisfies it. The
@@ -42,6 +42,8 @@ function toSiteProfile(value) {
42
42
  const { email, telephone } = contact;
43
43
  if (email !== null && typeof email !== "string") return null;
44
44
  if (telephone !== null && typeof telephone !== "string") return null;
45
+ const legal = toLegal(record.legal);
46
+ if (legal === void 0) return null;
45
47
  return {
46
48
  revision: record.revision,
47
49
  name: name === null ? null : name.trim() || null,
@@ -49,9 +51,26 @@ function toSiteProfile(value) {
49
51
  // A profile link that is not https is dropped, not repaired: a wrong `sameAs` claims an
50
52
  // identity the shop may not hold.
51
53
  sameAs: sameAs.map((url) => url.trim()).filter(isHttpsUrl),
52
- contact: { email: email?.trim() || null, telephone: telephone?.trim() || null }
54
+ contact: { email: email?.trim() || null, telephone: telephone?.trim() || null },
55
+ legal
53
56
  };
54
57
  }
58
+ function toLegal(value) {
59
+ if (value === void 0 || value === null) return null;
60
+ if (typeof value !== "object") return void 0;
61
+ const { kennitala, ...parts } = value;
62
+ if (typeof kennitala !== "string" || kennitala.trim() === "") return void 0;
63
+ const text = (part) => part === void 0 || part === null ? null : typeof part === "string" ? part.trim() || null : void 0;
64
+ const legal = {
65
+ name: text(parts.name),
66
+ kennitala: kennitala.trim(),
67
+ streetAddress: text(parts.streetAddress),
68
+ postalCode: text(parts.postalCode),
69
+ city: text(parts.city),
70
+ countryCode: text(parts.countryCode)
71
+ };
72
+ return Object.values(legal).includes(void 0) ? void 0 : legal;
73
+ }
55
74
  function isHttpsUrl(value) {
56
75
  try {
57
76
  return new URL(value).protocol === "https:";
@@ -64,6 +83,7 @@ export function resolveSiteProfile(setting, defaults) {
64
83
  name: setting?.name ?? defaults.siteName,
65
84
  logoUrl: setting?.logoUrl ?? defaults.iconLogoUrl,
66
85
  sameAs: setting?.sameAs ?? [],
67
- contact: setting?.contact ?? { email: null, telephone: null }
86
+ contact: setting?.contact ?? { email: null, telephone: null },
87
+ legal: setting?.legal ?? null
68
88
  };
69
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-nuxt",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "Nuxt module for Eldra themes: wires @eldrajs/vite-plugin-theme, the gateway client, draft overlays and the Studio preview bridge into a Nuxt 4 site.",
5
5
  "keywords": [
6
6
  "cms",
@@ -50,10 +50,10 @@
50
50
  "dependencies": {
51
51
  "@nuxt/kit": "^4.0.0",
52
52
  "defu": "^6.1.4",
53
- "@eldrajs/sdk": "^0.3.2",
54
- "@eldrajs/theme-core": "^0.3.1",
55
- "@eldrajs/vite-plugin-theme": "^0.3.1",
56
- "@eldrajs/theme-vue": "^0.2.2"
53
+ "@eldrajs/sdk": "^0.4.0",
54
+ "@eldrajs/theme-vue": "^0.2.3",
55
+ "@eldrajs/theme-core": "^0.3.2",
56
+ "@eldrajs/vite-plugin-theme": "^0.3.2"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@nuxt/module-builder": "^0.8.4",