|
| 1 | +# gaoo.js |
| 2 | + |
| 3 | +> Simple Google Analytics Opt-Out helper. |
| 4 | +
|
| 5 | +`gaoo.js` is a small helper script to [opt-out][ga-optout] from Google Analytics Tracking. |
| 6 | + |
| 7 | +It uses local storage to remember an opt-out and will set a `window` |
| 8 | +property which Google Analytics [inspects][ga-optout] to decide whether to track or not. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +```js |
| 13 | +// Initialize on page load. This needs to be called before ga.js is executed. |
| 14 | +window.gaoo('UA-123456-1'); |
| 15 | + |
| 16 | +// Actively opt-out from Google Analytics tracking. |
| 17 | +window.gaoo('UA-123456-1').enable(); |
| 18 | + |
| 19 | +// Actively opt-in to Google Analytics tracking, again. |
| 20 | +window.gaoo('UA-123456-1').disable(); |
| 21 | + |
| 22 | +// Check if currently opted out. |
| 23 | +if(window.gaoo('UA-123456-1').check()) { |
| 24 | + window.console.log('Currently opted out.'); |
| 25 | +} |
| 26 | + |
| 27 | +// Get opt-out identification string. |
| 28 | +var identifier = window.gaoo('UA-123456-1').identifier; |
| 29 | +``` |
| 30 | + |
| 31 | +### Examples |
| 32 | + |
| 33 | +**jQuery Example** |
| 34 | +```html |
| 35 | +<button class="opt-out">Opt-Out now.</button> |
| 36 | +<button class="opt-in">Opt-in again.</button> |
| 37 | + |
| 38 | +<script> |
| 39 | + // Initialize gaoo.js and create a reference. |
| 40 | + var helper = window.gaoo('UA-123456-1'); |
| 41 | + |
| 42 | + $('.opt-out').on('click', function(event) { |
| 43 | + helper.enable(); |
| 44 | + event.preventDefault(); |
| 45 | + }); |
| 46 | + |
| 47 | + $('.opt-in').on('click', function(event) { |
| 48 | + helper.disable(); |
| 49 | + event.preventDefault(); |
| 50 | + }); |
| 51 | +</script> |
| 52 | +``` |
| 53 | + |
| 54 | +## FAQ |
| 55 | + |
| 56 | +**Which browsers does `gaoo.js` support?** |
| 57 | +Supported are all browsers which implement local storage. |
| 58 | + |
| 59 | +**Can multiple Google Analytics properties be configured?** |
| 60 | +Currently it's not possible to define multiple properties to opt-out from. |
| 61 | + |
| 62 | +**Can domains be configured to opt-out from?** |
| 63 | +Opting out works for the current `protocol://host:port` combination only. |
0 commit comments