use store instead of localStorage to disable GoatCounter

This commit is contained in:
Son NK 2020-02-05 14:30:27 +07:00
parent 54e4f5e721
commit b40278f4dc
2 changed files with 5 additions and 2 deletions

View File

@ -412,10 +412,12 @@ def setup_do_not_track(app):
@app.route("/dnt") @app.route("/dnt")
def do_not_track(): def do_not_track():
return """ return """
<script src="/static/local-storage-polyfill.js"></script>
<script> <script>
// Disable GoatCounter if this script is called // Disable GoatCounter if this script is called
window.localStorage.setItem('goatcounter-ignore', 't'); store.set('goatcounter-ignore', 't');
alert("GoatCounter disabled"); alert("GoatCounter disabled");

View File

@ -174,6 +174,7 @@
{% block script %} {% block script %}
{% endblock %} {% endblock %}
<script src="/static/local-storage-polyfill.js"></script>
<script> <script>
(function () { (function () {
// only enable on prod // only enable on prod
@ -182,7 +183,7 @@
return; return;
} }
if (localStorage.getItem('goatcounter-ignore') === 't') { if (store.get('goatcounter-ignore') === 't') {
console.log("GoatCounter is disabled"); console.log("GoatCounter is disabled");
return; return;
} }