Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 52c86d1

Browse files
author
Thomas Deinhamer
committed
Merge branch 'release/0.1.0'
2 parents 6a77583 + a234f3f commit 52c86d1

File tree

10 files changed

+230
-0
lines changed

10 files changed

+230
-0
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = tab
6+
end_of_line = lf
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.md]
11+
indent_style = space
12+
indent_size = 2
13+
trim_trailing_whitespace = false
14+
15+
[{package,bower}.json]
16+
indent_style = space
17+
indent_size = 2

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Development
2+
/node_modules/

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log
2+
3+
## [next]
4+
5+
## [0.1.0] - 2016-02-04
6+
7+
### Added
8+
- Initial release
9+
10+
[next]: https://github.com/thasmo/gaoo.js/compare/v0.1.0...HEAD
11+
[0.1.0]: https://github.com/thasmo/gaoo.js/compare/6a775835e85ecf763257abe3322b282ba171b5ad...v0.1.0

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Thomas "Thasmo" Deinhamer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.

dist/gaoo.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// gulpfile.js
2+
3+
var gulp = require('gulp');
4+
var $ = require('gulp-load-plugins')();
5+
6+
var watch = {};
7+
var helper = {
8+
error: $.notify.onError({
9+
title: '<%= error.plugin %>',
10+
message: '<%= error.message %>'
11+
}),
12+
13+
success: function (task, message) {
14+
$.notify.logLevel(1);
15+
16+
return $.notify({
17+
title: task,
18+
message: message || 'Task finished.',
19+
onLast: true
20+
});
21+
},
22+
23+
watch: function(glob, tasks) {
24+
var hash = glob + tasks.join();
25+
26+
if(!$.util.env.watch && !$.util.env.w || watch[hash]) {
27+
return;
28+
}
29+
30+
watch[hash] = true;
31+
gulp.watch(glob, tasks);
32+
33+
$.util.log(
34+
'Watching',
35+
'\'' + $.util.colors.cyan(glob) + '\'',
36+
'for tasks',
37+
'\'' + $.util.colors.cyan(tasks.join(',')) + '\'',
38+
'...'
39+
);
40+
}
41+
};
42+
43+
// Default
44+
gulp.task('default', function() {
45+
var name = 'Default';
46+
47+
helper.watch('src/*.js', ['default']);
48+
49+
return gulp.src('src/*.js')
50+
.pipe($.plumber(helper.error))
51+
.pipe($.xo({quiet: true}))
52+
.pipe($.uglify())
53+
.pipe($.rename({extname: '.min.js'}))
54+
.pipe(gulp.dest('dist/'))
55+
.pipe(helper.success(name));
56+
});

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "gaoo.js",
3+
"description": "Simple Google Analytics Opt-Out helper.",
4+
"license": "MIT",
5+
"repository": {
6+
"type": "git",
7+
"url": "http://github.com/thasmo/gaoo.js"
8+
},
9+
"devDependencies": {
10+
"gulp": "~3.9",
11+
"gulp-util": "~3.0",
12+
"gulp-plumber": "~1.0",
13+
"gulp-load-plugins": "~1.1",
14+
"gulp-uglify": "~1.5",
15+
"gulp-rename": "~1.2",
16+
"gulp-notify": "~2.2",
17+
"gulp-xo": "~0.7",
18+
"del": "~2.1",
19+
"require-dir": "~0.3",
20+
"run-sequence": "~1.1"
21+
},
22+
"xo": {
23+
"envs": ["browser"]
24+
}
25+
}

src/gaoo.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(function (window) {
2+
'use strict';
3+
4+
var gaoo = function (key) {
5+
var identifier = 'ga-disable-' + key;
6+
var storageKey = 'gaoo';
7+
8+
var enable = function () {
9+
window[identifier] = true;
10+
window.localStorage.setItem(storageKey, true);
11+
};
12+
13+
var disable = function () {
14+
window[identifier] = false;
15+
window.localStorage.removeItem(storageKey);
16+
};
17+
18+
var check = function () {
19+
return window.localStorage.getItem(storageKey) !== null;
20+
};
21+
22+
window[identifier] = window[identifier] || check();
23+
24+
return {
25+
enable: enable,
26+
disable: disable,
27+
check: check,
28+
identifier: identifier
29+
};
30+
};
31+
32+
window.gaoo = gaoo;
33+
})(window);

0 commit comments

Comments
 (0)