Added -DNOGA=1 flag to disable Google Analytics

This commit is contained in:
Thulinma 2018-04-12 15:31:32 +02:00
parent 712fec11d5
commit 662f1cfa9d
2 changed files with 19 additions and 0 deletions

View file

@ -520,6 +520,11 @@ set(lspSOURCES
${SOURCE_DIR}/lsp/minified.js ${SOURCE_DIR}/lsp/minified.js
) )
if (NOT DEFINED NOGA )
list(APPEND lspSOURCES ${SOURCE_DIR}/lsp/analytics.js)
endif()
add_custom_command(OUTPUT ${BINARY_DIR}/generated/server.html add_custom_command(OUTPUT ${BINARY_DIR}/generated/server.html
COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR="${SOURCE_DIR}" -DlspSOURCES="${lspSOURCES}" -P ${SOURCE_DIR}/CMakeServHtml.txt COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR="${SOURCE_DIR}" -DlspSOURCES="${lspSOURCES}" -P ${SOURCE_DIR}/CMakeServHtml.txt
DEPENDS ${lspSOURCES} ${SOURCE_DIR}/CMakeServHtml.txt ${SOURCE_DIR}/lsp/main.css ${SOURCE_DIR}/lsp/header.html ${SOURCE_DIR}/lsp/footer.html DEPENDS ${lspSOURCES} ${SOURCE_DIR}/CMakeServHtml.txt ${SOURCE_DIR}/lsp/main.css ${SOURCE_DIR}/lsp/header.html ${SOURCE_DIR}/lsp/footer.html

14
lsp/analytics.js Normal file
View file

@ -0,0 +1,14 @@
//Google analytics. Can be fully disabled on request (or, if compiling yourself, add the NOGA=1 cmake flag).
//Is also disabled if the browser has the do not track flag setting turned on.
var oldTab = UI.showTab;
UI.showTab = function(){
 var r = oldTab.apply(this,arguments);
 if ((!navigator.doNotTrack) && (mist.user.loggedin)) {
   UI.elements.main.append(
     $("<img>").attr("src","https://www.google-analytics.com/collect?v=1&tid=UA-32426932-1&cid="+mist.data.config.iid+"&t=pageview&dp="+encodeURIComponent("/MI/"+arguments[0])+"&dh=MI."+(mist.data.LTS ? "Pro" : "OS")).css({width:"1px",height:"1px","min-width":"1px",opacity:0.1,position:"absolute",left:"-1000px"})
   );
 }
 return r;
};