Add onclick telemetry

pull/27/head
Urban Guacamole 4 years ago
parent dd341ba88b
commit 8dabe0d215

@ -17,7 +17,6 @@ Expecting a future where clickstream data are more and more important, because r
- torrent size
- session id
- action #
- rank #
- screen resolution
- expected to be critical for ranking of video
- User Agent

@ -2,6 +2,7 @@ function searchTriggered() {
let searchbox = document.getElementById("searchbox");
let query = searchbox.value
searchFor(query);
passQueryToResultpage(query)
}
async function searchFor(query) {
@ -23,24 +24,11 @@ function passResultToResultpage(results) {
results: JSON.stringify(results)
}, '*');
}
/**
* Sends telemetry payload, adds actionid and sessionid to it. IP is never logged.
*/
function sendTelemetry(payload){
payload.aid = actionid;
actionid = actionid + 1
if (sessionid == undefined){
sessionid = Math.round((Math.random()-0.5)*Math.pow(2,32))
payload.sid = sessionid;
}else{
payload.sid = sessionid;
}
(async (payload) => {
await fetch('https://torrent-paradise.ml/api/telemetry', {
method: 'POST',
body: JSON.stringify(payload)
})
})(payload);
function passQueryToResultpage(query) {
let resultPageIframe = document.getElementById("resultPage");
resultPageIframe.contentWindow.postMessage({
type: "query",
query: query
}, '*');
}

@ -13,7 +13,7 @@
<span v-bind:title="props.row.text">{{ props.row.text }}</span>
</b-table-column>
<b-table-column field="len" label="Size">
{{ props.row.len }}
{{ props.row.length }}
</b-table-column>
<b-table-column field="s" label="Seed" numeric sortable>
{{ props.row.s }}
@ -23,7 +23,7 @@
</b-table-column>
<b-table-column field="id" label=" " e>
<span class="icon">
<a style="color: hsl(171, 100%, 41%)" v-bind:href="'magnet:?xt=urn:btih:' + props.row.id + '&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337'">
<a style="color: hsl(171, 100%, 41%)" @click="resultClicked(props.row.id,props.row.text,props.row.s,props.row.l,props.row.len)" v-bind:href="'magnet:?xt=urn:btih:' + props.row.id + '&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337'">
<i class="fas fa-magnet"></i>
</a>
</span>
@ -33,5 +33,6 @@
</div>
<script src="../assets/vue-v2.6.11.js"></script>
<script src="buefy-table.js"></script>
<script src="platform.js"></script>
<script src="main.js"></script>
</body>

@ -8,23 +8,23 @@ app = new Vue({
}
})
let actionid = 0
let sessionid
let query
window.onmessage = function(e){
if (e.data.type == "results") {
let results = JSON.parse(e.data.results)
app.results = results.map((result) => {
result.len = formatBytes(result.len)
result.length = formatBytes(result.len)
return result
})
app.resultsFound = true
setTimeout(updateSize,1)
} else if (e.data.type == "progress") {
if(e.data.progress == 1){
app.showProgress = false
}else{
app.showProgress = true
}
app.progress = e.data.progress * 100
setTimeout(updateSize,1)
} else if (e.data.type == "query") {
query = e.data.query
console.log("Query sent, sending limited anonymized telemetry.")
sendTelemetry({"query":query})
}
};
@ -32,4 +32,37 @@ function updateSize(){
window.parent.postMessage(parseInt(document.body.scrollHeight),"*")
}
function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]}
function formatBytes(a,b){if(0==a)return"0 Bytes";var c=1024,d=b||2,e=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],f=Math.floor(Math.log(a)/Math.log(c));return parseFloat((a/Math.pow(c,f)).toFixed(d))+" "+e[f]}
/**
* Sends telemetry payload, adds actionid and sessionid to it. IP is never logged.
*/
function sendTelemetry(payload){
payload.aid = actionid;
actionid = actionid + 1
if (sessionid == undefined){
sessionid = Math.round((Math.random()-0.5)*Math.pow(2,32))
payload.sid = sessionid;
}else{
payload.sid = sessionid;
}
fetch('https://torrent-paradise.ml/api/telemetry', {
method: 'POST',
body: JSON.stringify(payload)
})
}
/**
* Reports anonymized data about which result you picked. Smart result sorting is planned and I expect that screen resolution, language and OS will be critical in determining which result you prefer.
*/
function resultClicked(ih,name,s,l,len){
console.log("Result clicked, sending limited anonymized telemetry")
payload = {ih: ih, n: name, s: s, l:l, len: len}
payload.os = platform.os
payload.w = window.screen.width*window.devicePixelRatio
payload.h = window.screen.height*window.devicePixelRatio
payload.lang = navigator.language || navigator.userLanguage
payload.query = query
sendTelemetry(payload)
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save