@structured-world/vue-privacy 1.1.0 → 1.1.2
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/dist/vitepress/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inBrowser } from "vitepress";
|
|
2
1
|
import { nextTick, watch } from "vue";
|
|
3
2
|
import { CONSENT_MANAGER_KEY, ConsentBanner as _sfc_main } from "../vue/index.js";
|
|
4
3
|
import { createConsentPlugin, useConsent } from "../vue/index.js";
|
|
@@ -16,7 +15,7 @@ function enhanceWithConsent(theme, config) {
|
|
|
16
15
|
ctx.app.provide("consentManager", manager);
|
|
17
16
|
ctx.app.provide(CONSENT_MANAGER_KEY, manager);
|
|
18
17
|
ctx.app.component("ConsentBanner", _sfc_main);
|
|
19
|
-
if (
|
|
18
|
+
if (typeof window !== "undefined") {
|
|
20
19
|
manager.init().then(() => {
|
|
21
20
|
nextTick(() => {
|
|
22
21
|
manager.trackPageView(window.location.pathname);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/vitepress/index.ts"],"sourcesContent":["import type { Theme } from \"vitepress\";\nimport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/vitepress/index.ts"],"sourcesContent":["import type { Theme } from \"vitepress\";\nimport { watch, nextTick } from \"vue\";\nimport type { ConsentConfig } from \"../core/types\";\nimport { createConsentPlugin, ConsentBanner, CONSENT_MANAGER_KEY } from \"../vue/index\";\nimport { createConsentManager } from \"../core/consent-manager\";\n\n/**\n * VitePress theme enhancement for cookie consent with SPA page tracking\n *\n * Automatically:\n * - Disables automatic page_view (SPA mode)\n * - Tracks initial page view after mount\n * - Watches Vue Router for SPA navigation and sends page_view events\n *\n * @example\n * ```ts\n * // docs/.vitepress/theme/index.ts\n * import DefaultTheme from 'vitepress/theme';\n * import { enhanceWithConsent } from '@structured-world/vue-privacy/vitepress';\n *\n * export default enhanceWithConsent(DefaultTheme, {\n * gaId: 'G-XXXXXXXXXX',\n * });\n * ```\n */\nexport function enhanceWithConsent(theme: Theme, config: ConsentConfig): Theme {\n return {\n ...theme,\n enhanceApp(ctx) {\n // Call original enhanceApp if exists\n theme.enhanceApp?.(ctx);\n\n // VitePress is a SPA — always disable automatic page_view and track\n // navigation manually via router watch. User's sendPageView is ignored.\n const manager = createConsentManager({\n ...config,\n sendPageView: false,\n });\n\n // Provide manager for injection (same keys as createConsentPlugin)\n ctx.app.provide(\"consentManager\", manager);\n ctx.app.provide(CONSENT_MANAGER_KEY, manager);\n\n // Register global component\n ctx.app.component(\"ConsentBanner\", ConsentBanner);\n\n // SSR-safe browser check — avoid importing inBrowser from vitepress\n // which is not available as a named export during SSR bundle compilation\n if (typeof window !== \"undefined\") {\n // Initialize consent manager\n manager\n .init()\n .then(() => {\n // Track initial page view after init completes.\n // For EU users with denied consent, Google Consent Mode accepts\n // the event but does not store it until consent is granted.\n nextTick(() => {\n manager.trackPageView(window.location.pathname);\n });\n })\n .catch((err) => {\n console.error(\"[@structured-world/vue-privacy] Failed to initialize:\", err);\n });\n\n // Track subsequent SPA navigations via router\n if (ctx.router) {\n watch(\n () => ctx.router.route.path,\n (path: string) => {\n // Wait for Vue to update DOM (including document.title)\n nextTick(() => {\n manager.trackPageView(path);\n });\n },\n // Initial page view is tracked after init(); don't fire on watch setup\n { immediate: false }\n );\n }\n }\n },\n };\n}\n\n/**\n * VitePress composable for adding consent banner to layout\n *\n * @example\n * ```ts\n * // docs/.vitepress/theme/index.ts\n * import DefaultTheme from 'vitepress/theme';\n * import { createConsentPlugin, ConsentBanner } from '@structured-world/vue-privacy/vitepress';\n * import { h } from 'vue';\n *\n * export default {\n * extends: DefaultTheme,\n * enhanceApp({ app }) {\n * app.use(createConsentPlugin({ gaId: 'G-XXX', sendPageView: false }));\n * },\n * Layout() {\n * return h(DefaultTheme.Layout, null, {\n * 'layout-bottom': () => h(ConsentBanner),\n * });\n * },\n * };\n * ```\n */\nexport { createConsentPlugin, ConsentBanner };\n\n// Re-export useConsent for convenience\nexport { useConsent } from \"../vue/index\";\n\n// Re-export core types\nexport type { ConsentConfig } from \"../core/types\";\n"],"names":["ConsentBanner"],"mappings":";;;;AAyBO,SAAS,mBAAmB,OAAc,QAA8B;AAC7E,SAAO;AAAA,IACL,GAAG;AAAA,IACH,WAAW,KAAK;;AAEd,kBAAM,eAAN,+BAAmB;AAInB,YAAM,UAAU,qBAAqB;AAAA,QACnC,GAAG;AAAA,QACH,cAAc;AAAA,MAAA,CACf;AAGD,UAAI,IAAI,QAAQ,kBAAkB,OAAO;AACzC,UAAI,IAAI,QAAQ,qBAAqB,OAAO;AAG5C,UAAI,IAAI,UAAU,iBAAiBA,SAAa;AAIhD,UAAI,OAAO,WAAW,aAAa;AAEjC,gBACG,OACA,KAAK,MAAM;AAIV,mBAAS,MAAM;AACb,oBAAQ,cAAc,OAAO,SAAS,QAAQ;AAAA,UAChD,CAAC;AAAA,QACH,CAAC,EACA,MAAM,CAAC,QAAQ;AACd,kBAAQ,MAAM,yDAAyD,GAAG;AAAA,QAC5E,CAAC;AAGH,YAAI,IAAI,QAAQ;AACd;AAAA,YACE,MAAM,IAAI,OAAO,MAAM;AAAA,YACvB,CAAC,SAAiB;AAEhB,uBAAS,MAAM;AACb,wBAAQ,cAAc,IAAI;AAAA,cAC5B,CAAC;AAAA,YACH;AAAA;AAAA,YAEA,EAAE,WAAW,MAAA;AAAA,UAAM;AAAA,QAEvB;AAAA,MACF;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@structured-world/vue-privacy",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Privacy-first consent & analytics for Vue 3, Nuxt 3, VitePress, and Quasar. GDPR/CCPA compliant with Google Consent Mode v2.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Dmitry Prudnikov <mail@polaz.com>",
|