1.2.0 • Published 5 years ago

rc-consent v1.2.0

Weekly downloads
2
License
-
Repository
github
Last release
5 years ago

Cookie Consent

A Vanilla JS plugin which meets General Data Protection Regulations (GDPR)

Demo

bower install rc-consent
npm install rc-consent
<script type="text/javascript" src="dist/rc-consent.js"></script>
<script type="text/javascript" id="rcc_consent_GA">
    window.addEventListener("DOMContentLoaded", function() {
        window.rcc.addProvider({
            id: 'ga',
            trackingId: 'UA-XXXXX-Y',
            anonymizeIp: true,
            load: function() {
                if (typeof ga === 'undefined') {
                    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
                        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
                    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
                }
            },
            onInitialise: function (rcc, status) {
                console.log('GA Consent init');

                if (rcc.hasConsented(this.category)) {
                    console.log('hasConsented: true');
                    ga('create', this.trackingId, 'auto');
                    ga('set', 'anonymizeIp', this.anonymizeIp);
                    ga('send', 'pageview');
                }
                else {
                    console.log('hasConsented: false');
                }
            },
            onAllow: function (rcc) {
                console.log('GA consent allow:' + this.category);

                this.load();
                ga('create', this.trackingId, 'auto');
                ga('set', 'anonymizeIp', this.anonymizeIp);
                ga('send', 'event', 'Cookie Consent', 'Accepted');
                ga('send', 'pageview');
            },
            onRevoke: function (rcc) {
                console.log('GA consent revoke:' + this.category);

                this.load();

                ga('create', this.trackingId, {'storage': 'none'});
                ga('send', 'event', 'Cookie Consent', 'Declined');
            }
        });
    });
</script>
<script>
    window.addEventListener("DOMContentLoaded", function() {
        window.rcc.initialise({
            cookie: {name: 'consent'}, 
            defaultStatus: {required: true}
        });
    });
</script>
//Simple example jQuery with modal foundation
(function($, rcc) {
    "use strict";

    var $consentModal = $('#consentModal');
    var $consentModalInstance = new Foundation.Reveal($consentModal);

    //Check has consented
    $( document ).ready(function() {

        if (!rcc.hasConsented()) {
            $consentModal.foundation('open');
        }
    });

    //On Submit close modal
    $('#consent_form').submit(function (e) {

        rcc.setConsent($consentModal.get(0));

        $consentModal.foundation('close');

        return false;
    });

    //Init form field on Modal Open
    $consentModal.on('open.zf.reveal', function () {

        rcc.setForm($consentModal.get(0));
    });

})(jQuery, rcc);
1.2.0

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago