mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
feat: Add --analytics-disable option to disable analytics tracking
This commit is contained in:
parent
5a28d499a8
commit
64df0ad590
3 changed files with 38 additions and 3 deletions
|
@ -12,16 +12,45 @@ from aider.dump import dump # noqa: F401
|
|||
|
||||
|
||||
class Analytics:
|
||||
def __init__(self, track, logfile=None):
|
||||
def __init__(self, track, logfile=None, disable=False):
|
||||
self.logfile = logfile
|
||||
if not track:
|
||||
self.disable = disable
|
||||
if not track or disable:
|
||||
self.mp = None
|
||||
if disable:
|
||||
self.mark_as_disabled()
|
||||
return
|
||||
|
||||
project_token = "6da9a43058a5d1b9f3353153921fb04d"
|
||||
self.mp = Mixpanel(project_token) if project_token else None
|
||||
self.user_id = self.get_or_create_uuid()
|
||||
|
||||
def mark_as_disabled(self):
|
||||
uuid_file = Path.home() / ".aider" / "caches" / "mixpanel.json"
|
||||
uuid_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
data = {"uuid": str(uuid.uuid4()), "disabled": True}
|
||||
with open(uuid_file, "w") as f:
|
||||
json.dump(data, f)
|
||||
|
||||
def get_or_create_uuid(self):
|
||||
uuid_file = Path.home() / ".aider" / "caches" / "mixpanel.json"
|
||||
uuid_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if uuid_file.exists():
|
||||
with open(uuid_file, "r") as f:
|
||||
data = json.load(f)
|
||||
if "disabled" in data and data["disabled"]:
|
||||
self.disable = True
|
||||
self.mp = None
|
||||
return data["uuid"]
|
||||
|
||||
new_uuid = str(uuid.uuid4())
|
||||
with open(uuid_file, "w") as f:
|
||||
json.dump({"uuid": new_uuid}, f)
|
||||
|
||||
return new_uuid
|
||||
|
||||
def get_system_info(self):
|
||||
return {
|
||||
"python_version": sys.version.split()[0],
|
||||
|
|
|
@ -558,6 +558,12 @@ def get_parser(default_config_files, git_root):
|
|||
metavar="ANALYTICS_LOG_FILE",
|
||||
help="Specify a file to log analytics events",
|
||||
)
|
||||
group.add_argument(
|
||||
"--analytics-disable",
|
||||
action="store_true",
|
||||
help="Disable analytics tracking and mark as disabled in mixpanel.json",
|
||||
default=False,
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
|
|
@ -373,7 +373,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
|||
editingmode=editing_mode,
|
||||
)
|
||||
|
||||
analytics = Analytics(args.analytics, logfile=args.analytics_log)
|
||||
analytics = Analytics(args.analytics, logfile=args.analytics_log, disable=args.analytics_disable)
|
||||
analytics.event("launched")
|
||||
|
||||
if args.gui and not return_coder:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue