-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1296 from Drakkar-Software/dev
Dev merge
- Loading branch information
Showing
7 changed files
with
165 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
Services/Interfaces/web_interface/static/js/common/tracking.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Services/Interfaces/web_interface/templates/components/community/user_details.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters