Skip to content

Vue Plugin API Reference ​

createConsentPlugin ​

Creates a Vue plugin for consent management.

typescript
import { createConsentPlugin } from "@structured-world/vue-privacy/vue";

app.use(createConsentPlugin(options));

Options ​

See ConsentConfig for all options.

useConsent ​

Composable for accessing consent state and methods.

typescript
import { useConsent } from "@structured-world/vue-privacy/vue";

const {
  getConsent,
  isConsentRequired,
  hasConsent,
  acceptAll,
  rejectAll,
  resetConsent,
  savePreferences,
} = useConsent();

Returns ​

Each member calls the manager method of the same name.

PropertyTypeDescription
getConsent() => StoredConsent | nullThe visitor's choice, or null while undecided
hasConsent() => booleanWhether the visitor has chosen (a grant or a refusal)
acceptAll() => Promise<void>Accept every category
rejectAll() => Promise<void>Refuse every optional category
savePreferences(categories) => Promise<void>Save a choice; a category not given is refused
resetConsent() => voidForget the choice and show the banner again
showPreferenceCenter() => voidOpen the preference centre
requestConsent(category, { reason }?) => Promise<boolean>Ask again for a category a feature needs; resolves whether it is granted
isConsentRequired() => boolean | nullWhether the visitor is in a consent jurisdiction
isCCPAUser() => booleanWhether the visitor is in a CCPA-covered US state (ccpaEnabled)
getRegion() => string | undefinedDetected region or US state
getGeoResult() => GeoDetectionResult | nullThe region lookup's result
trackPageView(path, title?) => voidTrack a page view (SPA navigation)
trackEvent(name, params?) => voidTrack a GA4 event
trackPurchase, trackAddToCart, trackBeginCheckout, trackViewItem, trackViewItemList, trackSelectItem, trackAddShippingInfo, trackAddPaymentInfo, trackSignUp, trackLogin, trackGenerateLeadGA4 recommended events (Ecommerce Tracking)
managerConsentManagerThe manager itself, e.g. for setLocale() and the dialog callbacks

ConsentPreferenceModal ​

The built-in preference centre. It opens through the manager (the banner's "Customize", showPreferenceCenter(), requestConsent()) and shows the categories in usedCategories, unticked for an undecided visitor.

PropTypeDefaultDescription
theme'auto' | 'light' | 'dark'the manager's theme, else 'auto'Colour palette
EventPayloadDescription
savethe saved categoriesEmitted after "Save preferences"
closeEmitted on accept all, reject all, or closing without a choice

ConsentBanner ​

Vue component for the consent banner.

vue
<ConsentBanner
  position="bottom"
  :config="{ title: 'Custom' }"
  @accept="onAccept"
  @reject="onReject"
  @customize="onCustomize"
/>

Props ​

PropTypeDefaultDescription
position'bottom' | 'top' | 'center''bottom'Banner position
configPartial<BannerConfig>{}Override banner config
theme'auto' | 'light' | 'dark'the manager's theme, else 'auto'Colour palette

Events ​

EventDescription
acceptEmitted when user accepts all
rejectEmitted when user rejects
customizeEmitted when user clicks customize

Slots ​

The component uses Teleport to render at body level. No slots available.

VitePress ​

enhanceWithConsent ​

Enhance a VitePress theme with consent.

typescript
import { enhanceWithConsent } from "@structured-world/vue-privacy/vitepress";

export default enhanceWithConsent(DefaultTheme, options);

Quasar ​

consentBoot ​

Create a Quasar boot function.

typescript
import { consentBoot } from "@structured-world/vue-privacy/quasar";

export default boot(consentBoot(options));

Released under the Apache 2.0 License. Powered by structured.world