This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Stats data capture feature
- Loading branch information
1 parent
dfea165
commit 76b89c0
Showing
3 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
|
||
µBlock.stats = (function () { | ||
|
||
var µb = µBlock; | ||
|
||
var reOS = /(CrOS\ \w+|Windows\ NT|Mac\ OS\ X|Linux)\ ([\d\._]+)?/; | ||
|
||
var matches = reOS.exec(navigator.userAgent); | ||
|
||
var operatingSystem = (matches || [])[1] || "Unknown"; | ||
|
||
var operatingSystemVersion = (matches || [])[2] || "Unknown"; | ||
|
||
var reBW = /(MSIE|Trident|(?!Gecko.+)Firefox|(?!AppleWebKit.+Chrome.+)Safari(?!.+Edge)|(?!AppleWebKit.+)Chrome(?!.+Edge)|(?!AppleWebKit.+Chrome.+Safari.+)Edge|AppleWebKit(?!.+Chrome|.+Safari)|Gecko(?!.+Firefox))(?: |\/)([\d\.apre]+)/; | ||
|
||
var matches = reBW.exec(navigator.userAgent); | ||
|
||
var browser = (matches || [])[1] || "Unknown"; | ||
|
||
var browserFlavor; | ||
|
||
if (window.opr) | ||
browserFlavor = "O"; // Opera | ||
else if (window.safari) | ||
browserFlavor = "S"; // Safari | ||
else if(browser == "Firefox") | ||
browserFlavor = "F"; // Firefox | ||
else | ||
browserFlavor = "E"; // Chrome | ||
|
||
var browserVersion = (matches || [])[2] || "Unknown"; | ||
|
||
var browserLanguage = navigator.language.match(/^[a-z]+/i)[0]; | ||
|
||
var storageStatsAttr = { | ||
userId: null, | ||
totalPings: 0 | ||
}; | ||
|
||
var exports = {}; | ||
|
||
var generateUserId = function() { | ||
|
||
var timeSuffix = (Date.now()) % 1e8; // 8 digits from end of timestamp | ||
|
||
var alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'; | ||
|
||
var result = []; | ||
|
||
for (var i = 0; i < 8; i++) { | ||
var choice = Math.floor(Math.random() * alphabet.length); | ||
|
||
result.push(alphabet[choice]); | ||
} | ||
return result.join('') + timeSuffix; | ||
} | ||
|
||
var ajaxCall = function(params){ | ||
console.log('Sending Stats Information'); | ||
var xhr = new XMLHttpRequest(); | ||
var url = "https://ping.ublock.org/api/stats" | ||
xhr.open('POST', url, true); | ||
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); | ||
xhr.overrideMimeType('text/html;charset=utf-8'); | ||
xhr.responseType = 'text'; | ||
xhr.onreadystatechange = function() { | ||
if(xhr.readyState == 4 && xhr.status == 200) { | ||
console.log(xhr.responseText); | ||
} | ||
} | ||
xhr.send(JSON.stringify(params)); | ||
} | ||
|
||
var getStatsEntries = function(callback) { | ||
|
||
if(storageStatsAttr.userId != null) { | ||
callback(storageStatsAttr); | ||
return; | ||
} | ||
var onDataReceived = function(data) { | ||
|
||
entries = data.stats || {userId: generateUserId(),totalPings: 0 }; | ||
|
||
storageStatsAttr = entries; | ||
|
||
callback(entries); | ||
} | ||
vAPI.storage.get('stats',onDataReceived); | ||
} | ||
|
||
exports.sendStats = function() { | ||
|
||
var processData = function(details) { | ||
|
||
details.totalPings = details.totalPings + 1; | ||
|
||
var statsData = { | ||
n: vAPI.app.name, | ||
v: vAPI.app.version, | ||
b: µb.localSettings.blockedRequestCount, | ||
a: µb.localSettings.allowedRequestCount, | ||
ad: µb.userSettings.advancedUserEnabled === true ? 1 : 0, | ||
df: µb.userSettings.dynamicFilteringEnabled === true ? 1 : 0, | ||
u: details.userId, | ||
f: browserFlavor, | ||
o: operatingSystem, | ||
bv: browserVersion, | ||
ov: operatingSystemVersion, | ||
l: browserLanguage | ||
} | ||
|
||
if (details.totalPings > 5000) { | ||
if (details.totalPings > 5000 && details.totalPings < 100000 && ((details.totalPings % 5000) !== 0)) { | ||
return; | ||
} | ||
if (details.totalPings >= 100000 && ((details.totalPings % 50000) !== 0)) { | ||
return; | ||
} | ||
} | ||
|
||
vAPI.storage.set({ 'stats': details }); | ||
|
||
if(browser == "Chrome") { | ||
if (chrome.management && chrome.management.getSelf) { | ||
chrome.management.getSelf(function(info) { | ||
statsData["it"] = info.installType.charAt(0); | ||
ajaxCall(statsData); | ||
}); | ||
} | ||
} | ||
else { | ||
ajaxCall(statsData); | ||
} | ||
scheduleStatsEvent(); | ||
} | ||
getStatsEntries(processData); | ||
} | ||
|
||
var scheduleStatsEvent = function() { | ||
|
||
var delayTiming = getNextScheduleTiming(function(delayTiming){ | ||
|
||
console.log('delayTiming = %O',delayTiming); | ||
|
||
µBlock.asyncJobs.add( | ||
'sendStats', | ||
null, | ||
µBlock.stats.bind(µBlock), | ||
delayTiming, | ||
true | ||
); | ||
}); | ||
} | ||
var getNextScheduleTiming = function(callback) { | ||
|
||
var processData = function(details) { | ||
|
||
var totalPings = details.totalPings; | ||
|
||
var delay_hours; | ||
|
||
delayHours = 1; | ||
|
||
if (totalPings == 1) // Ping one hour after install | ||
delayHours = 1; | ||
else if (totalPings < 9) // Then every day for a week | ||
delayHours = 24; | ||
else // Then weekly forever | ||
delayHours = 24 * 7 ; | ||
|
||
var millis = 1000 * 60 * 60 * delayHours; | ||
|
||
callback(millis); | ||
} | ||
|
||
getStatsEntries(processData); | ||
} | ||
|
||
exports.sendStats(); | ||
|
||
return exports; | ||
|
||
}); | ||
|
||
µBlock.stats(); |
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary? Ad blocking is to help users block tracking of them, not just providing the information to someone else.
Please reconsider this change.
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not enough donations? shame on you
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does uBlock need this information for? This needs to be reverted... fast.
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ublock origin, not this scam.
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He's not going to do anything, it's been added over a month ago, so how about you all remove this junk and install uBlock Origin ?
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basic debug info we use to ensure the extensions are running properly. This data is not being used to do anything other than to give us a sense of where our code is running and to help us identify issues. Thanks.
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah use uBlock Origin.
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the user id generator seems like a perfect example of what not to do.
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pgl @yous
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smed79 Added.
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uBlockAdmin You can track the stats of who’s downloading and using the extension perfectly fine on your own website.
I won’t beg you to change it. I won’t bother trying to campaign against you. Because I don’t even need to do any of that. I’ll just let you know what’s obvious to me and everyone else here: that including code for tracking & fingerprinting in a program billed to block tracking & fingerprinting is a surefire way to lose users. Good luck.
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're kidding me, right?
76b89c0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Facebook.