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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trustarc/react-cookie-consent-manager

v1.0.2

Published

React components to integrate TrustArc Cookie Consent Manager into React Frameworks

Readme

TrustArc React Cookie Consent

Welcome to the TrustArc React Cookie Consent Manager component! This library is designed to help clients using React frameworks integrate TrustArc Cookie Consent banners and related components seamlessly, while avoiding hydration issues during unmounts.

This is a beta project, and we are actively improving it based on your feedback. Please feel free to share your thoughts and suggestions!


Installation

This package supports React 18 and React 19 (and matching React DOM versions) in the consuming application. New installations are recommended to use React 19.

To install the package, use the following command:

npm install @trustarc/react-cookie-consent-manager

Building the Component

Before using or publishing the package, ensure it's built properly:

npm install  # Install dependencies
npm run build  # Generate the production-ready bundle

Tested Frameworks

This library has been tested with the following frameworks:

  • Next.js
  • Gatsby
  • Vite (React)
  • Preact
  • React.js (18.x and 19.x)

If you encounter issues with other frameworks, please let us know!


How It Works

This component provides a set of TrustArc-related components that can be easily integrated into your React application. It ensures that TrustArc scripts and banners are properly mounted and unmounted without causing hydration issues.

Key Features:

  • Dynamically injects TrustArc scripts into your application.
  • Provides reusable components for cookie consent banners, cookie preferences links, and IRM links.
  • Designed to minimize unnecessary mounts/unmounts by recommending usage in a layout component.

Example Usage

We recommend adding TrustArc components in a layout to avoid unnecessary mount/unmount cycles. Below is an example of how to use the library in a Layout component:

import React, { CSSProperties } from "react";
import { Link } from "react-router-dom";
import { createTrustArcComponents } from "@trustarc/react-cookie-consent-manager";

interface LayoutProps {
  children: React.ReactNode;
}

const Layout: React.FC<LayoutProps> = ({ children }) => {
  
  const {
    TrustArcScript,
    TrustArcConsentBanner,
    TrustArcCookiePreferencesLink,
    TrustArcIRMLink,
  // Placeholder for additional TrustArc components or configurations
  // Update this section with any custom TrustArc components or options as needed
  } = createTrustArcComponents("<YOURINSTANCEID>", {
    cookiePreferencesContainer: "teconsent",
    debug: true,
  });

  return (
    <div style={styles.container}>
      {/* Header */}
      <TrustArcScript />
      <TrustArcConsentBanner />
      <header style={styles.header}>
        <h1>TrustArc Demo</h1>
        <nav>
          <Link to="/" style={styles.link}>Home</Link>
          <Link to="/about" style={styles.link}>About</Link>
        </nav>
      </header>

      {/* Page Content */}
      <main style={styles.content}>{children}</main>

      {/* Footer with Cookie Preferences */}
      <footer style={styles.footer}>
        <TrustArcCookiePreferencesLink />
        <TrustArcIRMLink />
        <p>© 2025 TrustArc. All rights reserved.</p>
      </footer>
    </div>
  );
};

const styles: { [key: string]: CSSProperties } = {
  container: { display: "flex", flexDirection: "column", minHeight: "100vh" },
  header: { background: "#0073e6", padding: "15px", textAlign: "center", color: "white" },
  content: { flex: 1, padding: "20px", textAlign: "center" },
  footer: { background: "#f1f1f1", padding: "15px", textAlign: "center", marginTop: "auto" },
  link: { margin: "0 10px", color: "white", textDecoration: "none", fontSize: "18px" },
};

export default Layout;

Available Parameters

Here is a list of all parameters available in the TrustArcOptions interface:

| Parameter | Type | Description | |----------------------------|-----------|-----------------------------------------------------------------------------| | cookiePreferencesContainer | string | The ID of the container where the cookie preferences link will be injected. | | showCookiePreferencesAsButton | boolean | Displays the "Cookie Preferences" link as a button if set to true. | | irmContainer | string | The ID of the container where the IRM link will be injected. | | js | string | Specifies the JavaScript type for the TrustArc script (e.g., nj). | | noticeType | string | Defines the type of notice to display (e.g., bb for banner). | | countryCodeorIP | string | Overrides dynamic IP detection with a country code or IP address. | | state | string | Pre-configures state-specific consent behavior (e.g., ca for California). | | language | string | Overrides browser language detection with a specific language code. | | pcookie | boolean | Enables or disables persistent cookies. | | behavior | string | Forces specific behavior for the consent manager (e.g., expressed). | | privacyPolicyLink | string | Overrides the default privacy policy link in the Consent Manager. | | ccmVersion | string | Specifies the version of the TrustArc Consent Manager (e.g., Pro). | | pn | string | Loads a specific page in the Consent Manager as the first screen. | | onclose | boolean | Allows closing the Consent Manager by clicking outside the frame. | | ostype | boolean | Uses radio buttons instead of sliders for the consent banner. | | fade | number | Time in milliseconds before the banner fades. | | px | number | Number of pixels the user must scroll before the banner collapses. | | cookiePolicyLink | string | Encoded URL for the cookie policy displayed as a button in the banner. | | privacypolicylink | string | Overrides the privacy policy link in the Consent Manager. | | loadScriptAsync | boolean | Loads the TrustArc script asynchronously if set to true. | | debug | boolean | Enables debug logging for troubleshooting. |

Changing Language at Runtime

To switch the consent experience to another language without a page reload, call createTrustArcComponents again with the new language, for example with useMemo:

const { TrustArcScript, TrustArcConsentBanner, TrustArcCookiePreferencesLink } = useMemo(
  () => createTrustArcComponents("<YOURINSTANCEID>", { ccmVersion: "pro", language }),
  [language]
);

When the resulting script URL differs from the one already on the page, TrustArcScript replaces the TrustArc script, which then loads with the new language. If the URL is unchanged, the existing script is kept.


Disclaimer

This library is provided as-is, and it is the client's responsibility to ensure proper integration and compliance with their specific requirements. While we strive to make this library robust and reliable, we recommend thorough testing in your environment before deploying it to production.


Feedback

We value your feedback! As this is a beta project, we are continuously improving it. Please reach out to our support team or your Technical Account Manager to share your thoughts, suggestions, or report any issues.

Thank you for using TrustArc React Cookie Consent!