Skip to content

Commit f1657fd

Browse files
committed
See impact of adblock in google analytics
As the note in the code says, it will be useful to know if ads are worth keeping or not. At the minute I am paying for server costs, it would be great if ads could contribute to this
1 parent 6be17c3 commit f1657fd

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

assets/js/application.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@ $(document).ready(function() {
22
$('.simple-tip').tooltip({position: 'top', delay: 25})
33
$('.dropdown-button').dropdown();
44

5+
{
6+
// (http://blog.dynamicdrive.com/detecting-adblock-on-your-site-and-logging-it-to-google-analytics/)
7+
// The ad revenue is not important, but it would be useful to know
8+
// how many users are using adblock to evaluate if ads should stay/go.
9+
// After all, it helps pays for the servers
10+
// This piece of code tests for adblock (roughly) and then records to google analytics
11+
var test = document.createElement('div');
12+
test.innerHTML = ' ';
13+
test.className = 'adsbox';
14+
document.body.appendChild(test);
15+
16+
setTimeout(function() {
17+
if(test.offsetHeight === 0) {
18+
ga('send', 'event', 'Ad Setting', 'Adblock', 'Enabled');
19+
}
20+
21+
test.remove();
22+
}, 300);
23+
}
24+
525
if($('.sandbox-container').length) {
626
$('button[data-sb-action]').on('click', function(e) {
727
e.preventDefault();

0 commit comments

Comments
 (0)