diff --git a/src/planscape/analytics/services.py b/src/planscape/analytics/services.py index b4275fe05..77dacc1cd 100644 --- a/src/planscape/analytics/services.py +++ b/src/planscape/analytics/services.py @@ -1,12 +1,20 @@ from typing import AnyStr + +from django.conf import settings from django.utils.timezone import now from analytics.tasks import async_collect_metric def collect_metric(event_name: AnyStr, **kwargs) -> None: + if not settings.ANALYTICS_ENABLED: + return + event_params = { "timestamp": now(), **kwargs } + if settings.ANALYTICS_DEBUG_MODE: + event_params.update({"debug_mode": True}) + async_collect_metric.delay(event_name, event_params) diff --git a/src/planscape/planscape/settings.py b/src/planscape/planscape/settings.py index 1283d2df4..2e2ebabf3 100644 --- a/src/planscape/planscape/settings.py +++ b/src/planscape/planscape/settings.py @@ -452,6 +452,8 @@ GDAL_CACHE_MAX = config("GDAL_CACHE_MAX", "15%") # Analytics +ANALYTICS_ENABLED = config("ANALYTICS_ENABLED", default=False) +ANALYTICS_DEBUG_MODE = config("ANALYTICS_DEBUG_MODE", default=False) FIREBASE_APP_ID = config("FIREBASE_APP_ID", default=None) FIREBASE_APP_INSTANCE_ID = config("FIREBASE_APP_INSTANCE_ID", default=None) FIREBASE_API_SECRET = config("FIREBASE_API_SECRET", default=None)