Skip to content

Commit 1bbc03e

Browse files
author
ComputerElite
committed
instead of storing ip store an unique identifier stored as cookie on clients browser
1 parent 3012d52 commit 1bbc03e

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

AnalyticsData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static AnalyticsData Recieve(ServerRequest request)
6868
if (!data.endpoint.EndsWith("/")) data.endpoint += "/";
6969
data.host = new Uri(data.fullUri).Host;
7070
data.uA = request.context.Request.UserAgent;
71-
data.remote = Hasher.GetSHA256OfString(Hasher.GetSHA256OfString(Hasher.GetSHA256OfString(Hasher.GetSHA256OfString(ip))));
71+
if (data.remote == "") throw new Exception("Analtic data does not contain remote token");
7272
data.duration = data.sideClose - data.sideOpen;
7373
if (data.duration < 0) throw new Exception("Some idiot made a manual request with negative duration.");
7474
data.openTime = TimeConverter.UnixTimeStampToDateTime(data.sideOpen);

Program.cs

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public void AddToServer(HttpServer httpServer)
160160
});
161161
warningSystemsAndSiteMetrics.Start();
162162
Logger.Log("Analytics will be send to " + collection.GetPublicAddress());
163+
server.AddRoute("GET", "/randomtoken", new Func<ServerRequest, bool>(request =>
164+
{
165+
request.SendString(RandomExtension.CreateToken());
166+
return true;
167+
}));
163168
server.AddRoute("POST", "/analytics", new Func<ServerRequest, bool>(request =>
164169
{
165170
string origin = request.context.Request.Headers.Get("Origin");

analytics.js

+34
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ var analytic = {
1212
screenHeight: window.screen.height
1313
}
1414

15+
var CAid = GetCookie("CAid")
16+
if(!CAid) {
17+
fetch(analyticsHosts.includes(window.location.origin) ? "/randomtoken" : analyticsHosts[0] + "randomtoken").then(res => {
18+
res.text().then(res => {
19+
CAid = res
20+
SetCookie("CAid", CAid, 90)
21+
analytic.remote = CAid
22+
})
23+
})
24+
} else {
25+
analytic.remote = CAid
26+
}
1527

1628
var sent = false
1729

@@ -29,4 +41,26 @@ function SendAnalytics() {
2941
let blob = new Blob([JSON.stringify(analytic)], headers);
3042

3143
navigator.sendBeacon(analyticsHosts.includes(window.location.origin) ? "/analytics" : analyticsHosts[0] + "analytics", blob)
44+
}
45+
46+
function GetCookie(cookieName) {
47+
var name = cookieName + "=";
48+
var ca = document.cookie.split(';');
49+
for (var i = 0; i < ca.length; i++) {
50+
var c = ca[i];
51+
while (c.charAt(0) == ' ') {
52+
c = c.substring(1);
53+
}
54+
if (c.indexOf(name) == 0) {
55+
return c.substring(name.length, c.length);
56+
}
57+
}
58+
return "";
59+
}
60+
61+
function SetCookie(name, value, expiration) {
62+
var d = new Date();
63+
d.setTime(d.getTime() + (expiration * 24 * 60 * 60 * 1000));
64+
var expires = "expires=" + d.toUTCString();
65+
document.cookie = name + "=" + value + ";" + expires + ";path=/";
3266
}

privacy.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ II. What data is being collected
99
- Full url of the visited site excluding query parameters
1010
- Exact time the site has been opened
1111
- Exact time the site has been closed
12+
- an unique id which is randomly generated to anonymise you in the data
1213
- The website or url you come from (e. g. If you clicked on a link on YouTube it'll be https://youtube.com)
1314
- Your devices screen width and height which may or may not be accurate
1415
2. Data by the http request (those are default with everything you send over the internet)
15-
- Your IP address. It is being used to count a estimate of individuals visiting the site{1}. It's being stored as hash so it's harder to assocate with someone. On top of that your IP address usually changes every few days/weeks.
1616
- Your User Agent. This is usually your browser and operating system
1717

1818
3. Data which is NOT being collected
@@ -38,5 +38,7 @@ III. How is the data being stored?
3838
How long is my data being stored?
3939
It is stored indefinetly or until there's no more storage space. On latter the oldeast Analytics will get deleted.
4040

41+
IV. Cookies
42+
Cookies are used to store your unique id which is being used to estimate the amount of users visiting the site
4143

4244
If there's anything which is needed or if there are any questions feel free to ask them on GitHub and answers will be added here. You can ask on https://github.com/ComputerElite/ComputerAnalytics/issues

0 commit comments

Comments
 (0)