Skip to content

Commit

Permalink
Merge pull request #1296 from Drakkar-Software/dev
Browse files Browse the repository at this point in the history
Dev merge
  • Loading branch information
GuillaumeDSM authored Jul 9, 2024
2 parents e2cc4b7 + 34c877c commit cc1a26d
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% import 'components/community/user_details.html' as m_user_details %}

<!doctype html>
<html lang="en" data-mdb-theme="{{get_color_mode()}}">
{% set active_page = active_page|default('advanced.home') -%}
Expand Down Expand Up @@ -42,6 +44,14 @@
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css', u=LAST_UPDATED_STATIC_FILES) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/layout.css', u=LAST_UPDATED_STATIC_FILES) }}">

{% if IS_DEMO or IS_CLOUD or IS_ALLOWING_TRACKING%}
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys getNextSurveyStep onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init('{{PH_TRACKING_ID}}',{api_host:'https://eu.i.posthog.com',
})
</script>
{% endif %}

{% block additional_style %}
{% endblock additional_style %}
</head>
Expand All @@ -67,6 +77,7 @@
<script src="{{ url_for('static', filename='js/common/bot_connection.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>
<script src="{{ url_for('static', filename='js/common/dom_updater.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>
<script src="{{ url_for('static', filename='js/common/required.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>
<script src="{{ url_for('static', filename='js/common/tracking.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>

<nav class="navbar navbar-expand-md py-0 py-md-2" id="main-nav-bar">
<div class="navbar-collapse collapse w-100 order-1 order-md-0 dual-collapse2">
Expand Down Expand Up @@ -125,5 +136,15 @@

{% block additional_scripts %}
{% endblock additional_scripts %}
{{ m_user_details.user_details(
IS_ALLOWING_TRACKING,
USER_EMAIL,
USER_SELECTED_BOT_ID,
has_open_source_package,
PROFILE_NAME,
TRADING_MODE_NAME,
EXCHANGE_NAMES,
IS_REAL_TRADING
) }}
</body>
</html>
21 changes: 21 additions & 0 deletions Services/Interfaces/web_interface/flask_util/context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
# License along with this library.
import octobot_commons.symbols.symbol_util as symbol_util
import octobot_commons.constants as commons_constants
import octobot_commons.authentication as authentication
import octobot.constants as constants
import octobot.enums as enums
import octobot.community.identifiers_provider as identifiers_provider
import octobot.community.supabase_backend.enums as community_enums
import tentacles.Services.Interfaces.web_interface.models as models
import tentacles.Services.Interfaces.web_interface.models.configuration as configuration_model
import tentacles.Services.Interfaces.web_interface.enums as web_enums
Expand Down Expand Up @@ -122,6 +124,18 @@ def get_enabled_tentacles(tentacles_info_by_name):
if info[web_constants.ACTIVATION_KEY]:
return name

def get_logged_in_email():
try:
return authentication.Authenticator.instance().get_logged_in_email()
except (authentication.AuthenticationRequired, authentication.UnavailableError):
return ""

current_profile = models.get_current_profile()
trading_mode = models.get_config_activated_trading_mode()
selected_bot = models.get_selected_user_bot()
selected_bot_id = (selected_bot.get(community_enums.BotKeys.ID.value) or "") if selected_bot else ""


return dict(
LAST_UPDATED_STATIC_FILES=web_interface.LAST_UPDATED_STATIC_FILES,
OCTOBOT_WEBSITE_URL=constants.OCTOBOT_WEBSITE_URL,
Expand All @@ -140,6 +154,13 @@ def get_enabled_tentacles(tentacles_info_by_name):
CAN_INSTALL_TENTACLES=constants.CAN_INSTALL_TENTACLES,
IS_ALLOWING_TRACKING=models.get_metrics_enabled(),
TRACKING_ID=constants.TRACKING_ID,
PH_TRACKING_ID=constants.PH_TRACKING_ID,
USER_EMAIL=get_logged_in_email(),
USER_SELECTED_BOT_ID=selected_bot_id,
PROFILE_NAME=current_profile.name,
TRADING_MODE_NAME=trading_mode.get_name() if trading_mode else "",
EXCHANGE_NAMES=",".join(get_profile_exchanges(current_profile)),
IS_REAL_TRADING=models.is_real_trading(current_profile),
TAB_START=web_enums.TabsLocation.START,
TAB_END=web_enums.TabsLocation.END,
get_color_mode=get_color_mode,
Expand Down
75 changes: 75 additions & 0 deletions Services/Interfaces/web_interface/static/js/common/tracking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

$(document).ready(function() {

const getUserEmail = () => {
return getUserDetails().email
}

const getUserDetails = () => {
return _USER_DETAILS
}

const updateUserDetails = () => {
posthog.capture(
getUserEmail(),
event='update_user_details',
properties={
'$set': getUserDetails(),
}
)
}

const shouldUpdateUserDetails = () => {
const currentProperties = posthog.get_property('$stored_person_properties');
return (
getUserEmail() !== ""
&& isDefined(currentProperties)
&& JSON.stringify(currentProperties) !== JSON.stringify(getUserDetails())
)
}

const shouldReset = (newEmail) => {
const previousId = posthog.get_distinct_id();
return (
newEmail !== previousId
// if @ is the user id, it's an email which is different from the current one: this is a new user
&& previousId.indexOf("@") !== -1
);
}

const identify = (email) => {
posthog.identify(
email,
getUserDetails() // optional: set additional person properties
);
}

const updateUserIfNecessary = () => {
if (!_IS_ALLOWING_TRACKING){
// tracking disabled
return
}
const email = getUserEmail();
if (email !== "" && posthog.get_distinct_id() !== email){
if (shouldReset(email)){
// If you also want to reset the device_id so that the device will be considered a new device in
// future events, you can pass true as an argument
// => past events will be bound to the current user as soon as he connects but avoid binding later events
// in case the user changes
console.log("PH: Resetting user")
const resetDeviceId = true
posthog.reset(resetDeviceId);
}
// new authenticated email: identify
console.log("PH: Identifying user")
identify(email);
}else{
if (shouldUpdateUserDetails()){
console.log("PH: updating user details")
updateUserDetails();
}
}
}

updateUserIfNecessary();
});
14 changes: 3 additions & 11 deletions Services/Interfaces/web_interface/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,9 @@ <h2>Help us to improve OctoBot</h2>
{% if not IS_CLOUD %}
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="metricsCheckbox" update-url="{{ url_for('metrics_settings') }}" {{ 'checked' if metrics_enabled else ''}}>
<label class="custom-control-label" for="metricsCheckbox">Share</label> anonymous data to help the OctoBot Community
<p>This will grant you access to the <a href="{{ url_for('community_metrics') }}"> OctoBot Community metrics</a> and greatly help the OctoBot team to figure out the best ways to improve OctoBot.
<i class="fa-solid fa-question" data-toggle="tooltip" data-placement="top"
title="Shared data are:
Bot version and running time, trader type, the name of used exchanges, tentacles, traded pairs, profile name and notification systems.
Overall portfolio value in reference market, traded volumes and profitability are shared to evaluate strategies performances.
Finally the current environment details OctoBot is running on and the way you support the project (if you are) are also shared as
well as if you are emitting or receiving signals and your web interface usage stats.
Nothing else is ever shared: no personal data, no identification enabling data.">
</i>
It won't slow your OctoBot down.
<label class="custom-control-label" for="metricsCheckbox">Share</label> metrics to help the OctoBot Community
<p>
This will greatly help the OctoBot team to figure out the best ways to improve OctoBot and won't slow your OctoBot down.
</p>
</div>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% macro user_details(
IS_ALLOWING_TRACKING,
USER_EMAIL,
USER_SELECTED_BOT_ID,
has_open_source_package,
PROFILE_NAME,
TRADING_MODE_NAME,
EXCHANGE_NAMES,
IS_REAL_TRADING)
-%}
<script>
const _IS_ALLOWING_TRACKING = {{ 'true' if IS_ALLOWING_TRACKING else 'false' }}
const _USER_DETAILS = {
email: "{{ USER_EMAIL }}",
botId: "{{ USER_SELECTED_BOT_ID }}",
hasPremiumExtension: {{ 'true' if has_open_source_package() else 'false'}},
profileName: "{{ PROFILE_NAME }}",
tradingMode: "{{ TRADING_MODE_NAME }}",
exchanges: "{{ EXCHANGE_NAMES }}".split(","),
isRealTrading: {{ 'true' if IS_REAL_TRADING else 'false' }},
}
</script>
{%- endmacro %}
22 changes: 21 additions & 1 deletion Services/Interfaces/web_interface/templates/layout.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% import 'macros/trading_state.html' as m_trading_state %}
{% import 'components/modals/trading_state_modal.html' as m_trading_state_modal %}
{% import 'components/modals/generic_modal.html' as m_generic_modal %}
{% import 'components/community/user_details.html' as m_user_details %}
<!doctype html>
<html lang="en" data-mdb-theme="{{get_color_mode()}}">
{% set active_page = active_page|default('home') -%}
Expand Down Expand Up @@ -57,6 +58,14 @@
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css', u=LAST_UPDATED_STATIC_FILES) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/layout.css', u=LAST_UPDATED_STATIC_FILES) }}">

{% if IS_DEMO or IS_CLOUD or IS_ALLOWING_TRACKING%}
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys getNextSurveyStep onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init('{{PH_TRACKING_ID}}',{api_host:'https://eu.i.posthog.com',
})
</script>
{% endif %}

{% block additional_style %}
{% endblock additional_style %}
</head>
Expand Down Expand Up @@ -88,7 +97,8 @@
<script src="{{ url_for('static', filename='js/common/required.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>
<script src="{{ url_for('static', filename='js/common/tutorial.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>
<script src="{{ url_for('static', filename='js/common/feedback.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>
{% if IS_DEMO or IS_CLOUD or IS_ALLOWING_TRACKING%}
<script src="{{ url_for('static', filename='js/common/tracking.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>
{% if IS_DEMO or IS_CLOUD or IS_ALLOWING_TRACKING%}
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
Expand Down Expand Up @@ -269,5 +279,15 @@ <h5 class="mb-0">
{% block additional_scripts %}
{% endblock additional_scripts %}
<script src="{{ url_for('static', filename='js/common/on_load.js', u=LAST_UPDATED_STATIC_FILES) }}"></script>
{{ m_user_details.user_details(
IS_ALLOWING_TRACKING,
USER_EMAIL,
USER_SELECTED_BOT_ID,
has_open_source_package,
PROFILE_NAME,
TRADING_MODE_NAME,
EXCHANGE_NAMES,
IS_REAL_TRADING
) }}
</body>
</html>
2 changes: 1 addition & 1 deletion Services/Interfaces/web_interface/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ <h4 class="alert-heading">Strategies</h4>
<div class="container-fluid row col-12">
<div class="col-md-6">
<label for="AddCurrencySelect">Add a cryptocurrency to trade:</label>
<select id="AddCurrencySelect" data-live-search="true"
<select id="AddCurrencySelect" data-live-search="true" data-window-padding="25"
reference_market="{{ config_reference_market }}" data-fetch-url="{{ url_for('api.currency_list') }}">

</select>
Expand Down

0 comments on commit cc1a26d

Please sign in to comment.