Socket
Socket
Sign inDemoInstall

@68publishers/cookie-consent-resolver

Package Overview
Dependencies
0
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @68publishers/cookie-consent-resolver

Inject scripts without waiting for the cookies widget to load!


Version published
Weekly downloads
4
increased by100%
Maintainers
2
Created
Weekly downloads
 

Changelog

Source

1.0.1 - 2023-05-17

Added

  • Added the LICENSE.md

Changed

  • Updated the README

Readme

Source

Utility for 68publishers/cookie-consent that allows you to inject scripts without waiting for the cookies widget to load!

Tests Coding style

Why

In some cases, it is desirable to run some scripts as soon as possible, and initializing the cookie widget may slow down the execution of these scripts. This package allows scripts to be injected into the page immediately if the user has already given consent.

Installation

The first option is to download the package as a module.

$ npm i --save @68publishers/cookie-consent-resolver
# or
$ yarn add @68publishers/cookie-consent-resolver

And import it in your project.

import CookieConsentResolver from '@68publishers/cookie-consent-resolver';
// or
const CookieConsentResolver = require('@68publishers/cookie-consent-resolver');

Or you can import the CookieConsentResolver into the browser from the CDN

<script src="https://unpkg.com/@68publishers/cookie-consent-resolver/dist/cookie-consent-resolver.min.js"></script>

Usage

var cookieConsentResolver = CookieConsentResolver.createFromCookie('cc-settings');

cookieConsentResolver.bindCookieConsentWrapper(CookieConsentWrapper);

// the following script will be injected if the `ad_storage` is enabled
cookieConsentResolver.injectScript('ad_storage', 'https://www.example.com/my-script.js');

// the following script will be injected if the `ad_storage` and `analytics_storage` are enabled
cookieConsentResolver.injectScript(['ad_storage', 'analytics_storage'], 'https://www.example.com/my-script2.js');

Additional <script> tag attributes can be provided in the third argument.

cookieConsentResolver.injectScript('ad_storage', 'https://www.example.com/my-script.js', {
  id: 'my-script',
  async: true,
});

If you want to do anything other than inject the script in case of consent, you can use the resolve() method.

cookieConsentResolver.resolve('ad_storage', () => {
  console.log('Ad storage is enabled!');
});

License

The package is distributed under the MIT License. See LICENSE for more information.

Keywords

FAQs

Last updated on 17 May 2023

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