1010
1111import os
1212from functools import wraps
13+ from hashlib import sha256
1314from http import HTTPStatus
1415
1516import click
@@ -49,11 +50,23 @@ def post(event_id):
4950 click .echo (f"INFO: Anonymous analytics has been disabled for /{ event_id } " )
5051 return
5152
52- actor_id = os .environ ["GITHUB_ACTOR_ID" ]
53+ # this is unique b/c the IP address is fixed. Both together represent
54+ # a unique user ID for Plausible
55+ actor_id = int .from_bytes (
56+ sha256 (
57+ os .environ .get ("GITHUB_TRIGGERING_ACTOR" , "" ).encode (),
58+ usedforsecurity = False ,
59+ ).digest ()
60+ )
5361 referrer = (
5462 os .environ ["GITHUB_SERVER_URL" ] + "/" + os .environ ["GITHUB_REPOSITORY_OWNER" ]
5563 )
56- ip_address = requests .get ("https://ifconfig.me" , timeout = 5 ).text
64+
65+ # Plausible.io rejects GitHub's original IP address b/c it is listed as a
66+ # datacenter address and we don't have information about the actual address of the
67+ # user who triggered our application. Instead just use a public address that
68+ # isn't going to be rejected
69+ ip_address = "176.12.5.83"
5770
5871 response = requests .post (
5972 "https://plausible.io/api/event" ,
@@ -67,7 +80,7 @@ def post(event_id):
6780 },
6881 },
6982 headers = {
70- "User-Agent" : f"kiwitcms-gitops/{ __version__ } . { actor_id } " ,
83+ "User-Agent" : f"kiwitcms-gitops/{ actor_id } " ,
7184 "X-Forwarded-For" : ip_address ,
7285 "Content-Type" : "application/json" ,
7386 },
0 commit comments