diff --git a/label_studio/core/context_processors.py b/label_studio/core/context_processors.py index 7fec686b791f..76b337958f8e 100644 --- a/label_studio/core/context_processors.py +++ b/label_studio/core/context_processors.py @@ -1,8 +1,13 @@ """This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license. """ +import os + from core.feature_flags import all_flags from core.utils.common import collect_versions from django.conf import settings as django_settings +from django.utils import timezone + +from label_studio.core.utils.io import get_config_dir def sentry_fe(request): @@ -33,3 +38,33 @@ def settings(request): feature_flags = all_flags(request.user) return {'settings': django_settings, 'versions': versions, 'feature_flags': feature_flags} + + +def frontend_events(request): + events = [] + if should_send_install_event(): + events.append( + { + 'name': 'setup.install', + 'with_iframe': True, + } + ) + return {'frontend_events': events} + + +_INSTALL_EVENT_SENT = False + + +def should_send_install_event(): + # Only fire install event once per instance + global _INSTALL_EVENT_SENT + if django_settings.VERSION_EDITION == 'Community' and not _INSTALL_EVENT_SENT: + install_file = os.path.join(get_config_dir(), 'install.txt') + if not os.path.exists(install_file): + with open(install_file, 'w') as f: + f.write(timezone.now().isoformat()) + _INSTALL_EVENT_SENT = True + return True + _INSTALL_EVENT_SENT = True + + return False diff --git a/label_studio/core/settings/base.py b/label_studio/core/settings/base.py index 6258a78710b3..4072c7018cbe 100644 --- a/label_studio/core/settings/base.py +++ b/label_studio/core/settings/base.py @@ -316,6 +316,7 @@ 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'core.context_processors.settings', + 'core.context_processors.frontend_events', ], 'builtins': ['django.templatetags.i18n'], }, diff --git a/label_studio/templates/base.html b/label_studio/templates/base.html index a9f31847752f..77e38eb12198 100644 --- a/label_studio/templates/base.html +++ b/label_studio/templates/base.html @@ -103,6 +103,7 @@ feature_flags_default_value: {{ settings.FEATURE_FLAGS_DEFAULT_VALUE|json_dumps_ensure_ascii|safe }}, server_id: {{ request.server_id|json_dumps_ensure_ascii|safe }}, collect_analytics: {{ settings.COLLECT_ANALYTICS|yesno:"true,false" }}, + frontend_events: {{ frontend_events|json_dumps_ensure_ascii|safe }}, {% block app_more_settings %} flags: { diff --git a/label_studio/templates/simple.html b/label_studio/templates/simple.html index b21fd945f840..90ed8af21604 100644 --- a/label_studio/templates/simple.html +++ b/label_studio/templates/simple.html @@ -1,5 +1,6 @@ {% load static %} {% load i18n %} +{% load filters %} @@ -29,6 +30,55 @@
+ {% block content %} {% endblock %} diff --git a/label_studio/users/templates/users/new-ui/user_tips.html b/label_studio/users/templates/users/new-ui/user_tips.html index 26ea96a31698..f6350bbbb51c 100644 --- a/label_studio/users/templates/users/new-ui/user_tips.html +++ b/label_studio/users/templates/users/new-ui/user_tips.html @@ -2,41 +2,6 @@