Socket
Socket
Sign inDemoInstall

@valu/tracking-blocker

Package Overview
Dependencies
1
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @valu/tracking-blocker

Implement GDPR cookie consents.


Version published
Weekly downloads
1
Maintainers
2
Install size
49.9 kB
Created
Weekly downloads
 

Readme

Source

Tracking Blocker

Implement GDPR cookie consents.

Uses yett for script blocking and custom implementation for iframe blocking.

Setup

npm install @valu/tracking-blocker

Traditional sites

Load node_modules/@valu/tracking-blocker/dist/tb-head.min.js before any scripts or iframes that send tracking beacons.

Next.js

In _document.tsx:

import Document, { Head, Html, Main, NextScript } from "next/document";

import { TrackingBlocker } from "@valu/tracking-blocker/react-ssr";

class MyDocument extends Document {
    render() {
        return (
            <Html>
                <Head>
                    <TrackingBlocker
                        scriptWhitelist={[/allow\.example/]}
                    ></TrackingBlocker>
                    <script
                        dangerouslySetInnerHTML={{
                            __html: `/* whatever tracking codes */`,
                        }}
                    ></script>
                </Head>
                <body>
                    <Main />
                    <NextScript />
                </body>
            </Html>
        );
    }
}

export default MyDocument;

React API

import { useTrackingBlocker } from "@valu/tracking-blocker/react";

function TrackingConsent() {
    const [blocked, api] = useTrackingBlocker();

    if (!blocked) {
        return null;
    }

    return (
        <div>
            <p>We use cookies.</p>
            <button onClick={api.unblock}>OK</button>
        </div>
    );
}

Global API

To be used with traditional websites

if (TB.isBlocked()) {
    $("#consent-prompt").show();
    $("#consent-prompt button").on("click", () => {
        TB.unblock();
    });
}

FAQs

Last updated on 15 Dec 2020

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