Socket
Socket
Sign inDemoInstall

@smg-automotive/cookie-consent-pkg

Package Overview
Dependencies
7
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @smg-automotive/cookie-consent-pkg

A boilerplate package setup


Version published
Weekly downloads
272
decreased by-1.81%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

CircleCI semantic-release

Usage

npm install @smg-automotive/cookie-consent-pkg

Loading OneTrust banner

OneTrustCookieConsentBanner adds the required script tags to the document head and preloads the script so that it loads as early as possible. only loads a 3KB script. All subsequent scripts load async.

import { OneTrustCookieConsentBanner } from '@smg-automotive/cookie-consent-pkg';

// loads using JavaScript. You may gain more performance by adding it manually to the server HTML
<OneTrustCookieConsentBanner domainScript="yourScriptID" enabled={true} />;

Alternatively, if you are serving an HTML from the server, consider adding it manually inside the document head.

<script
    src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js"
    data-domain-script="yourScriptID"
    data-document-language="true"
/>

CookieConsentProvider

You should wrap your application with the CookieConsentProvider. It places listeners on the current cookie consent and enables you to react on changes (e.g. block certain third party scripts).

<CookieConsentProvider
  enabled={true}
  onConsentChanged={(newConsent) => console.log(newConsent)}
  onOneTrustLoaded={(initialConsent, hideBanner) => console.log(initialConsent)}
>
  <div>your app..</div>
</CookieConsentProvider>

onConsentChanged is optional and allows you to fire events when the user changed the consent in the preference center. onOneTrustLoaded is optional and is called after OneTrust has been loaded. hideBanner is true if the banner has been shown in a previous session.

CookieConsentContext

You can get the current consent and other properties related to cookie consent in your component using useCookieConsent hook.

import { useCookieConsent } from '@smg-automotive/cookie-consent-pkg';

const { consent, openPreferenceCenter, isLoaded, hasInteracted } =
  useCookieConsent;
propertytypedescription
consentCategory[]Array of the current consent. If the user uses a script blocker or you disabled OneTrust in the Provider, only the stricly necessary category is set.
openPreferenceCenterFunctionOpens the OneTrust preference center.
isLoadedbooleanTrue if OneTrust has been successfully loaded and invoked.
hasInteractedbooleanTrue if the user has interacted with the banner at some point.

Development

npm run build

You can link your local npm package to integrate it with any local project:

cd cookie-consent-pkg
npm run build

cd <project directory>
npm link ../cookie-consent-pkg

Release a new version

New versions are released on the ci using semantic-release as soon as you merge into master. Please make sure your merge commit message adheres to the corresponding conventions and your branch name does not contain forward slashes /.

FAQs

Last updated on 18 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc