Giter Site home page Giter Site logo

dallasread / gdpr-google-analytics Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 2.0 549 KB

Need to make Google Analytics GDPR-Compliant?

Home Page: https://dallasread.github.io/gdpr-google-analytics

HTML 64.47% JavaScript 35.53%
gdpr gdpr-cookie gdpr-checklist gdpr-tracker

gdpr-google-analytics's Introduction

Need to make Google Analytics GDPR-Compliant?

Make this one small change to your Analytics embed snippet:

(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.gdpr-google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXX-1', 'auto');
ga('send', 'pageview');

Done!

Does it work with other tracking services (eg. GTM, Mixpanel, Segment)?

Yes โ€” with only a little re-jigging! Insert the following snippet prior to your other tracking snippets. Add the URL of each service as a dependency. To ensure the trackers don't load by themselves, you'll want to remove any X.src=XXXX; code in your original tracking snippets. That's it!

<script>
    (function(g,d,p,r){g[p]=g[p]||function(a,b,c){
    g[d]=g[d]||{};g[d][a]=g[d][a]||[];g[d][a].push([b,c]);};
    })(window,'GDPRGoogleAnalytics','gdpr');

    gdpr('dependency', 'https://www.googletagmanager.com/gtm.js?id=XXXXXXXX');
</script>
<script src="https://www.gdpr-google-analytics.com/analytics.js"></script>

Need to change something?

gdpr('vars', 'buttonColor', 'red');
gdpr('vars', 'buttonText', '&check; Accept!');
gdpr('vars', 'content', 'By clicking "Accept All Cookies"...');
gdpr('vars', 'policyURL', 'http://example.com/');
gdpr('vars', 'policyText', 'See Our Privacy Policy');

Need to know when the terms have been accepted?

gdpr('on', 'accept', function() {
    alert('Terms have just been accepted!');
});

Any CSS can be overridden in the .gdpr-google-analytics-notice element.

The full size of this library is ~4.66 kb.

Any questions? Look at this page's source.

gdpr-google-analytics's People

Contributors

dallasread avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

jianweic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.