fix: Disable analytics by default and provide option to enable

This commit is contained in:
Paul Gauthier 2024-08-13 08:08:05 -07:00 committed by Paul Gauthier (aider)
parent 4ebbfa01b7
commit aeadf2f139
3 changed files with 20 additions and 6 deletions

View file

@ -10,10 +10,15 @@ from mixpanel import Mixpanel
from aider import __version__
from aider.dump import dump # noqa: F401
DATA_FILE_NAME = "mixpanel.json"
project_token = "6da9a43058a5d1b9f3353153921fb04d"
class Analytics:
mp = None
user_id = None
disable = None
logfile = None
def __init__(self, track, logfile=None, disable=False):
self.logfile = logfile
self.disable = disable
@ -23,12 +28,13 @@ class Analytics:
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()
if self.user_id and not self.disable:
self.mp = Mixpanel(project_token)
def get_data_file_path(self):
data_file = Path.home() / ".aider" / "caches" / DATA_FILE_NAME
data_file = Path.home() / ".aider" / "analytics.json"
data_file.parent.mkdir(parents=True, exist_ok=True)
return data_file
@ -44,9 +50,11 @@ class Analytics:
if data_file.exists():
with open(data_file, "r") as f:
data = json.load(f)
dump(data)
if "disabled" in data and data["disabled"]:
self.disable = True
self.mp = None
return
return data["uuid"]
new_uuid = str(uuid.uuid4())

View file

@ -334,6 +334,11 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
# Parse again to include any arguments that might have been defined in .env
args = parser.parse_args(argv)
if args.analytics_disable:
analytics = Analytics(track=False, disable=True)
print("Analytics have been permanently disabled.")
return
if not args.verify_ssl:
import httpx

View file

@ -7,7 +7,8 @@ nav_order: 500
Aider uses MixPanel to collect anonymous analytics that are used to help
improve aider.
**Analytics is currently turned off by default**, but expected to be turned on by default in
**Analytics are currently turned off by default**, but are
expected to be turned on by default in
a future release.
## Anonymous, no personal info
@ -35,7 +36,7 @@ personal use of aider.
## Enabling & disabling analytics
You can easily opt out of analytics forever by running this command one time:
You can opt out of analytics forever by running this command one time:
```
aider --analytics-disable