|
74 | 74 | # The preview cards shown when a DigiFacts link is shared (cards/: the PNGs, and the HTML they were drawn from). |
75 | 75 | # Each DigiFact always uses the same one (chosen by its ID), so a feed of DigiFacts alternates between them. |
76 | 76 | CARDS = ["cards/card-1.png", "cards/card-2.png"] |
| 77 | +# Tags that say where a short link was shown, e.g. https://go.diginode.tools/7ttm?dnt - counted as the click's source |
| 78 | +# ("DigiNode Tools"). Any other tag is counted as itself. QR codes can't contain "?" (they'd lose their compact |
| 79 | +# mode) - the capitals links count as "QR code" instead. |
| 80 | +SOURCE_TAGS = {"dnt": "DigiNode Tools", "bsky": "Bluesky", "tg": "Telegram", "x": "X"} |
77 | 81 | USER_AGENT = f"DigiFacts builder ({REPO_URL})" |
78 | 82 |
|
79 | 83 | LANGUAGE_NAMES = { |
@@ -580,7 +584,12 @@ def redirect_page(url, key, title, qr, number=0, text=""): |
580 | 584 | u = html.escape(url, quote=True) |
581 | 585 | count = urllib.parse.urlencode({"p": "/" + key, "t": title, "r": "QR code" if qr else ""}) |
582 | 586 | script = (f"try{{var c={json.dumps(STATS_URL + '/count?' + count)};" |
583 | | - + ("" if qr else "if(document.referrer)c=c.replace('&r=','&r='+encodeURIComponent(document.referrer));") |
| 587 | + + ("" if qr else |
| 588 | + # Where the click came from: a tag on the link (e.g. ?dnt from DigiNode Tools - see SOURCE_TAGS), or |
| 589 | + # else the website it was on |
| 590 | + f"var v=(location.search.match(/^\\?([a-z0-9-]{{1,20}})/i)||[])[1],n={json.dumps(SOURCE_TAGS)};" |
| 591 | + "if(v)c=c.replace('&r=','&r='+encodeURIComponent(n[v.toLowerCase()]||v));" |
| 592 | + "else if(document.referrer)c=c.replace('&r=','&r='+encodeURIComponent(document.referrer));") |
584 | 593 | + "c+='&rnd='+Math.random().toString(36).slice(2);" |
585 | 594 | "if(navigator.sendBeacon)navigator.sendBeacon(c);else(new Image()).src=c}catch(e){}" |
586 | 595 | f"location.replace({json.dumps(url)})").replace("</", "<\\/") |
|
0 commit comments