Skip to content
4 changes: 4 additions & 0 deletions src/assets/ba_data/python/babase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from _babase import (
add_clean_frame_callback,
allows_ticket_sales,
analytics_disable,
android_get_external_files_dir,
app_instance_uuid,
appname,
Expand Down Expand Up @@ -71,6 +72,7 @@
in_main_menu,
increment_analytics_count,
request_main_ui,
is_analytics_enabled,
is_os_playing_music,
is_xcode_build,
lock_all_input,
Expand Down Expand Up @@ -220,6 +222,7 @@
'ActorNotFoundError',
'allows_ticket_sales',
'add_clean_frame_callback',
'analytics_disable',
'android_get_external_files_dir',
'app',
'App',
Expand Down Expand Up @@ -309,6 +312,7 @@
'InputDeviceNotFoundError',
'InputType',
'request_main_ui',
'is_analytics_enabled',
'is_browser_likely_available',
'is_browser_likely_available',
'is_os_playing_music',
Expand Down
4 changes: 4 additions & 0 deletions src/assets/ba_data/python/babase/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def __init__(self) -> None:
self._subsystem_property_lock = RLock()
self._subsystem_property_data: dict[str, AppSubsystem | bool] = {}

_babase.analytics_disable(
not self.config.get('Analytics Enabled', True)
)

@property
def active(self) -> bool:
"""Whether the app is currently front and center.
Expand Down
59 changes: 33 additions & 26 deletions src/assets/ba_data/python/bauiv1lib/settings/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
from typing import TYPE_CHECKING, override

import babase
from bacommon.locale import LocaleResolved
import bauiv1 as bui
from bauiv1lib.utils import scroll_fade_bottom, scroll_fade_top
Expand Down Expand Up @@ -675,6 +676,23 @@ def _rebuild(self) -> None:
else:
self._always_use_internal_keyboard_check_box = None

v -= 42
self._toggle_analytics_checkbox = cbw = bui.checkboxwidget(
parent=self._subcontainer,
id=f'{self.main_window_id_prefix}|toggleanalytics',
position=(50, v),
size=(self._sub_width - 100, 30),
autoselect=True,
maxwidth=430,
textcolor=(0.8, 0.8, 0.8),
value=babase.is_analytics_enabled(),
text=bui.Lstr(value='Enable Analytics'),
# (resource=f'{self._r}.enableAnalytics'),
on_value_change_call=bui.WeakCallPartial(
self._on_toggle_analytics_value_change
),
)

v -= self._spacing * 2.1

this_button_width = 410
Expand All @@ -691,6 +709,16 @@ def _rebuild(self) -> None:
),
)

assert cbw is not None
bui.widget(
edit=cbw,
down_widget=self._modding_guide_button,
)
bui.widget(
edit=self._modding_guide_button,
up_widget=cbw,
)

v -= self._spacing * 2.0

self._dev_tools_button = bui.buttonwidget(
Expand All @@ -704,32 +732,6 @@ def _rebuild(self) -> None:
on_activate_call=self._on_dev_tools_button_press,
)

if self._show_always_use_internal_keyboard:
assert self._always_use_internal_keyboard_check_box is not None
bui.widget(
edit=self._always_use_internal_keyboard_check_box.widget,
down_widget=self._modding_guide_button,
)
bui.widget(
edit=self._modding_guide_button,
up_widget=self._always_use_internal_keyboard_check_box.widget,
)
else:
# ew.
next_widget_up = (
self._disable_gyro_check_box.widget
if self._disable_gyro_check_box is not None
else self._disable_camera_shake_check_box.widget
)
bui.widget(
edit=self._modding_guide_button,
up_widget=next_widget_up,
)
bui.widget(
edit=next_widget_up,
down_widget=self._modding_guide_button,
)

v -= self._spacing * 2.0

self._show_user_mods_button = bui.buttonwidget(
Expand Down Expand Up @@ -839,6 +841,11 @@ def _on_lang_inform_value_change(self, val: bool) -> None:
)
plus.run_v1_account_transactions()

def _on_toggle_analytics_value_change(self, val: bool) -> None:
babase.analytics_disable(not val)
bui.app.config['Analytics Enabled'] = val
bui.app.config.apply_and_commit()

def _on_vr_test_press(self) -> None:
from bauiv1lib.settings.vrtesting import VRTestingWindow

Expand Down
74 changes: 68 additions & 6 deletions src/ballistica/base/python/methods/python_methods_base_3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,58 @@ static PyMethodDef PyMarkLogSentDef = {
":meta private:",
};

// --------------------- analytics_disable -----------------------------

auto PyAnalyticsDisable(PyObject* self, PyObject* args, PyObject* keywds)
-> PyObject* {
BA_PYTHON_TRY;
int value = 1;
static const char* kwlist[] = {"value", nullptr};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|p",
const_cast<char**>(kwlist), &value)) {
return nullptr;
}
g_core->platform->AnalyticsIsEnabled = !value;
Py_RETURN_NONE;
BA_PYTHON_CATCH;
}

static PyMethodDef PyAnalyticsDisableDef = {
"analytics_disable", // name
(PyCFunction)PyAnalyticsDisable, // method
METH_VARARGS | METH_KEYWORDS, // flags

"analytics_disable(value: bool = True) -> None\n"
"\n"
"Used to disable analytics collection if desired.\n"
"\n"
":meta private:",
};

// --------------------- is_analytics_enabled -----------------------------

auto PyIsAnalyticsEnabled(PyObject* self, PyObject* args) -> PyObject* {
BA_PYTHON_TRY;
if (g_core->platform->AnalyticsIsEnabled) {
Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
BA_PYTHON_CATCH;
}

static PyMethodDef PyIsAnalyticsEnabledDef = {
"is_analytics_enabled", // name
(PyCFunction)PyIsAnalyticsEnabled, // method
METH_VARARGS, // flags

"is_analytics_enabled() -> bool\n"
"\n"
"Returns a boolean value to show if Analytics is enabled.\n"
"\n"
":meta private:",
};

// --------------------- increment_analytics_count -----------------------------

auto PyIncrementAnalyticsCount(PyObject* self, PyObject* args, PyObject* keywds)
Expand All @@ -1074,7 +1126,8 @@ auto PyIncrementAnalyticsCount(PyObject* self, PyObject* args, PyObject* keywds)
int increment = 1;
static const char* kwlist[] = {"name", "increment", nullptr};
if (!PyArg_ParseTupleAndKeywords(
args, keywds, "s|p", const_cast<char**>(kwlist), &name, &increment))
args, keywds, "s|p", const_cast<char**>(kwlist), &name, &increment)
&& g_core->platform->AnalyticsIsEnabled)
g_core->platform->IncrementAnalyticsCount(name, increment);
Py_RETURN_NONE;
BA_PYTHON_CATCH;
Expand All @@ -1099,7 +1152,8 @@ static auto PyIncrementAnalyticsCountRaw(PyObject* self, PyObject* args,
int increment = 1;
static const char* kwlist[] = {"name", "increment", nullptr};
if (!PyArg_ParseTupleAndKeywords(
args, keywds, "s|i", const_cast<char**>(kwlist), &name, &increment))
args, keywds, "s|i", const_cast<char**>(kwlist), &name, &increment)
&& g_core->platform->AnalyticsIsEnabled)
g_core->platform->IncrementAnalyticsCountRaw(name, increment);
Py_RETURN_NONE;
BA_PYTHON_CATCH;
Expand Down Expand Up @@ -1130,8 +1184,10 @@ static auto PyIncrementAnalyticsCountRaw2(PyObject* self, PyObject* args,
&uses_increment, &increment)) {
return nullptr;
}
g_core->platform->IncrementAnalyticsCountRaw2(name, uses_increment,
increment);
if (g_core->platform->AnalyticsIsEnabled) {
g_core->platform->IncrementAnalyticsCountRaw2(name, uses_increment,
increment);
}
Py_RETURN_NONE;
BA_PYTHON_CATCH;
}
Expand All @@ -1152,7 +1208,9 @@ static PyMethodDef PyIncrementAnalyticsCountRaw2Def = {
static auto PySubmitAnalyticsCounts(PyObject* self, PyObject* args,
PyObject* keywds) -> PyObject* {
BA_PYTHON_TRY;
g_core->platform->SubmitAnalyticsCounts();
if (g_core->platform->AnalyticsIsEnabled) {
g_core->platform->SubmitAnalyticsCounts();
}
Py_RETURN_NONE;
BA_PYTHON_CATCH;
}
Expand All @@ -1178,7 +1236,9 @@ static auto PySetAnalyticsScreen(PyObject* self, PyObject* args,
const_cast<char**>(kwlist), &screen)) {
return nullptr;
}
g_core->platform->SetAnalyticsScreen(screen);
if (g_core->platform->AnalyticsIsEnabled) {
g_core->platform->SetAnalyticsScreen(screen);
}
Py_RETURN_NONE;
BA_PYTHON_CATCH;
}
Expand Down Expand Up @@ -2179,6 +2239,8 @@ auto PythonMoethodsBase3::GetMethods() -> std::vector<PyMethodDef> {
PySetAnalyticsScreenDef,
PyLoginAdapterGetSignInTokenDef,
PyLoginAdapterBackEndActiveChangeDef,
PyAnalyticsDisableDef,
PyIsAnalyticsEnabledDef,
PySubmitAnalyticsCountsDef,
PyIncrementAnalyticsCountRawDef,
PyIncrementAnalyticsCountRaw2Def,
Expand Down
1 change: 1 addition & 0 deletions src/ballistica/core/platform/core_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CorePlatform {
public:
/// Instantiate the CorePlatform subclass for the current build.
static auto Create() -> CorePlatform*;
bool AnalyticsIsEnabled = true;

#pragma mark LIFECYCLE/SETTINGS ------------------------------------------------

Expand Down
Loading