npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@wix/consent-policy-manager

v1.10.0

Published

Wix Consent Policy SDK package for GDPR and CCPA compliance

Downloads

3,234

Readme

@wix/consent-policy-manager

A type-safe Wix Consent Policy SDK for managing site visitor cookie preferences and 3rd-party data transfers for GDPR and CCPA compliance. This package provides a browser-only interface that proxies to the global window.consentPolicyManager methods with full TypeScript support.

Installation

npm install @wix/consent-policy-manager

Quick Start

import {
  getCurrentConsentPolicy,
  setConsentPolicy,
  resetConsentPolicy,
  onConsentPolicyChanged,
} from "@wix/consent-policy-manager";

// Get current consent policy
const policyDetails = getCurrentConsentPolicy();
if (policyDetails) {
  console.log("Current policy:", policyDetails.policy);
  console.log("Is default policy:", policyDetails.defaultPolicy);
  console.log("Created date:", policyDetails.createdDate);
} else {
  console.log("No consent policy available");
}

// Set a new consent policy
const newPolicy = {
  essential: true,      // Always true - required for Wix websites
  functional: true,     // Remember user settings
  analytics: false,     // Analytics cookies (Google Analytics, etc.)
  advertising: false,   // Advertising cookies and pixels
  dataToThirdParty: false, // Data transfer to 3rd parties
};

const result = await setConsentPolicy(newPolicy);
if (result) {
  console.log("Policy updated:", result);
} else {
  console.log("Failed to update policy");
}

// Reset to default policy
const resetSuccess = resetConsentPolicy();
if (resetSuccess) {
  console.log("Policy reset to default");
} else {
  console.log("Failed to reset policy or no policy to reset");
}

// Listen for consent policy changes
onConsentPolicyChanged((event) => {
  console.log("Consent policy changed!");
  console.log("New policy:", event.policy);
  console.log("Is default policy:", event.defaultPolicy);
});

Features

  • Type-safe - Full TypeScript support for all consent policy operations
  • GDPR/CCPA compliant - Helps manage visitor privacy preferences
  • Browser-only - Works in Wix applications where window.consentPolicyManager is available
  • Zero dependencies - Lightweight proxy implementation
  • Silent failure - Graceful handling of missing dependencies with console warnings
  • Event-driven - Listen for consent policy changes in real-time
  • Comprehensive API - Full access to consent policy, headers, and event publishing

API Reference

getCurrentConsentPolicy()

Gets the site visitor's current consent policy regarding allowed cookies and 3rd-party data transfers.

Returns: PolicyDetails | undefined

const policyDetails = getCurrentConsentPolicy();
if (policyDetails) {
  // {
  //   defaultPolicy: false,
  //   policy: {
  //     essential: true,
  //     functional: true,
  //     analytics: true,
  //     advertising: false,
  //     dataToThirdParty: false
  //   },
  //   createdDate: Date
  // }
}

setConsentPolicy(policy)

Sets the current site visitor's consent policy regarding allowed cookies and data transfer to 3rd parties.

Parameters:

  • policy - Policy object with boolean values for each consent type

Returns: Promise<PolicyDetails | undefined>

const policy = {
  essential: true,        // Required - always true
  functional: true,       // Optional - user preference cookies
  analytics: false,       // Optional - analytics tracking
  advertising: false,     // Optional - advertising cookies
  dataToThirdParty: false // Optional - 3rd party data transfer
};

const result = await setConsentPolicy(policy);
if (result) {
  console.log("Policy set successfully:", result);
}

resetConsentPolicy()

Removes the current policy from the site visitor's browser and resets to the default site policy.

Returns: boolean | undefined

const success = resetConsentPolicy();
if (success) {
  console.log("Policy reset successfully");
}

onConsentPolicyChanged(handler)

Registers a callback function that is triggered when a site visitor's consent policy is changed using setConsentPolicy() or reset using resetConsentPolicy().

Parameters:

  • handler - Callback function that receives the consent policy change event

Returns: void

onConsentPolicyChanged((event) => {
  console.log("Consent policy changed!");
  console.log("New policy:", event.policy);
  console.log("Is default policy:", event.defaultPolicy);
  
  // Example: Update analytics based on new policy
  if (event.policy.analytics) {
    // Enable analytics tracking
  } else {
    // Disable analytics tracking
  }
});

// Example event object:
// {
//   "defaultPolicy": false,
//   "policy": {
//     "essential": true,
//     "functional": false,
//     "analytics": true,
//     "advertising": false,
//     "dataToThirdParty": false
//   }
// }

Policy Types

Policy

The consent policy settings object:

interface Policy {
  essential: boolean;      // Always true - required cookies
  functional: boolean;     // User preference cookies
  analytics: boolean;      // Analytics tracking cookies
  advertising: boolean;    // Advertising and marketing cookies
  dataToThirdParty: boolean; // 3rd party data transfer consent
}

PolicyDetails

Complete consent policy information:

interface PolicyDetails {
  defaultPolicy: boolean;  // Whether using default site policy
  policy: Policy;         // The actual policy settings
  createdDate?: Date;     // When policy was set (optional)
}