Created
July 19, 2015 13:20
-
-
Save thyngster/f511a4f1c48515d9bb59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* Spam Referrals Buster | |
* | |
* author: David Vallejo (@thyng) | |
* version: 0.2 Beta | |
* date: 2015-07-19 | |
* | |
* @link https://www.thyngster.com | |
*/ | |
(function(){ | |
var getStrippedDomain = function (url) { | |
var a=document.createElement('a'); | |
a.href=url; | |
if (a.hostname.substring(0,4)=="www.") { | |
a.hostname=a.hostname.substring(4,a.hostname.length); | |
} | |
return a.hostname; | |
} | |
// domain hash routine from urchin.js | |
var generateDomainHash = function generateDomainHash(d) | |
{ | |
if (!d || d=="") return 1; | |
var h=0,g=0; | |
for (var i=d.length-1;i>=0;i--){ | |
var c=parseInt(d.charCodeAt(i)); | |
h=((h << 6) & 0xfffffff) + c + (c << 14); | |
if ((g=h & 0xfe00000)!=0) h=(h ^ (g >> 21)); | |
} | |
return h; | |
} | |
var currentDomain = getStrippedDomain(location.hostname); | |
var currentReferrer = getStrippedDomain(document.referrer); | |
if(currentDomain!=currentReferrer) | |
{ | |
// List of referrals taking from Piwik website | |
// https://github.com/piwik/referrer-spam-blacklist (2015-07-19) | |
// Domains are hashed to improve performance. | |
var blockDomains = [263039757, 34007457, 55065771, 120081032, 26509560, 177333665, 49917920, 179660596, 54583931, 223710155, 262814300, 9477733, 227758541, 180169332, 74254082, 107575378, 156219627, 81867974, 260947933, 241848658, 68743809, 100663633, 259344346, 92805709, 154818280, 66544254, 90401610, 21838571, 180691319, 40491698, 161276909, 228896076, 218653450, 236698258, 199269949, 139910816, 15197733, 212879495, 89031944, 45107895, 156446760, 60097982, 92289550, 23099433, 253356250, 47900916, 193629310, 138291619, 267519837, 28886511, 66298109, 112011863, 132223517, 174536497, 236918930, 146907684, 101321874, 52305723, 210629511, 44250934, 227859215, 239842065, 220961674, 12598181, 177897015, 2834210, 92936079, 257686937, 65584572, 129268638, 194356927, 247275537, 187924413, 180255153, 31164458, 151219372, 11188769, 30110250, 98217802, 127491608, 34343092, 19514413, 26086056, 123546078, 109015895, 269593445, 145229344, 14118499, 157319342, 108747926, 119536157, 170625268, 17197805, 75630209, 202202629, 237263380, 120789660, 241326614, 78112704, 45898739, 34775926, 83705217, 264499608, 226197261, 192682813, 98378696, 25279722, 225216845, 190742972, 68926343, 12888481, 253399839, 211691715, 30357161, 96803849, 174647540, 50565951, 78196482, 117663263, 179948082, 5340074, 239429786, 191908787, 131045142, 247679774, 34656824, 119773649, 53412656, 255172368, 250014942, 82290894, 256272211, 151627489, 163122148, 155788131, 192958581, 259457938, 32766502, 23338722, 106227739, 11385900, 203407945, 170261627, 215481229, 12682925, 52999090, 14939692, 11418542, 57528880, 186878450, 112925470, 33142819, 208158223, 136238764, 250524827, 38514623, 50206266, 155556903, 213518856, 35495229, 132051987, 117297562, 114228379, 240058015, 173866559, 89708551, 4652847, 88425607, 144682409, 76982665, 20660260, 261539474, 26581794, 46480889, 191281652, 99458048, 116177816, 83671944, 39742141, 92111428, 113906054, 178312613, 182536551, 180588710, 138442290, 104487169, 130201486, 203151376, 184532647, 159674236, 140297970, 255970378, 120227657, 215762518, 233644639, 171443617, 268032526, 64260911, 218110746, 106928000, 101061378, 109542662, 214885524, 136675379, 59102766, 140101552, 69930259, 246799110, 179534502, 261660303, 113628933, 190416681, 171884578, 69094803, 203312147, 52522410, 60214959, 260003208, 55348713, 82094420, 232875612, 223271705, 259179784, 10959670, 150111220, 24590584, 256476489, 227512095, 264618125, 260541455, 154056634, 173667361, 91450264, 74558544, 105796289, 106987584, 138748977, 57121832, 109374976, 74068247, 133437067, 157207806, 226943000, 83231635, 180578914, 115705027, 188893231, 265531211, 227914778, 194976682, 5925684, 18074686, 66591913, 66573609, 149298992, 44053282, 8444595, 42906531, 67125655, 194580005, 192774690, 201007782, 235211401, 34498602, 259665032, 209136158, 181346027, 148579321, 246840116, 189388895]; | |
if(blockDomains.indexOf(generateDomainHash(currentReferrer))>-1) | |
{ | |
// Block using js opt-out | |
var property_id = 'UA-XXXXXX-Y'; | |
window['ga-disable-'+property_id] = true; | |
// if you prefer it you can send a push to the dataLayer to block your tags. | |
// dataLayer.push({'blockTracking': true}); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment