add GoatCounter analytics
This commit is contained in:
parent
5053d343d1
commit
35aa8f1438
18
server.py
18
server.py
|
@ -89,6 +89,7 @@ def create_app() -> Flask:
|
|||
|
||||
init_admin(app)
|
||||
setup_paddle_callback(app)
|
||||
setup_do_not_track(app)
|
||||
|
||||
if FLASK_PROFILER_PATH:
|
||||
LOG.d("Enable flask-profiler")
|
||||
|
@ -401,6 +402,23 @@ def init_admin(app):
|
|||
admin.add_view(SLModelView(ClientUser, db.session))
|
||||
|
||||
|
||||
def setup_do_not_track(app):
|
||||
@app.route("/dnt")
|
||||
def do_not_track():
|
||||
return """
|
||||
<script>
|
||||
// Disable GoatCounter if this script is called
|
||||
|
||||
window.localStorage.setItem('goatcounter-ignore', 't');
|
||||
|
||||
alert("GoatCounter disabled");
|
||||
|
||||
window.location.href = "/";
|
||||
|
||||
</script>
|
||||
"""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = create_app()
|
||||
|
||||
|
|
|
@ -128,5 +128,30 @@
|
|||
{% block script %}
|
||||
{% endblock %}
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
// only enable on prod
|
||||
if (!window.location.host.endsWith('simplelogin.io')) {
|
||||
console.log("GoatCounter should only be enabled in prod");
|
||||
return;
|
||||
}
|
||||
|
||||
if (localStorage.getItem('goatcounter-ignore') === 't') {
|
||||
console.log("GoatCounter is disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("init GoatCounter");
|
||||
|
||||
var script = document.createElement('script');
|
||||
window.counter = 'https://app.goatcounter.com/count'
|
||||
script.async = 1;
|
||||
script.src = '//gc.zgo.at/count.js';
|
||||
|
||||
var ins = document.getElementsByTagName('script')[0];
|
||||
ins.parentNode.insertBefore(script, ins)
|
||||
})();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue