Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebInterface] also send info before login #1314

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{% 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',
posthog.init('{{PH_TRACKING_ID}}',{api_host:'https://eu.i.posthog.com', person_profiles: 'always'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows to set user properties before explicitely calling "identify"

})
</script>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function register_exchanges_checks(check_existing_accounts){

const check_account = (exchangeCard, source, newValue) => {
const exchange = exchangeCard.find(".card-body").attr("name");
if(exchange !== config_default_value){
if(exchange !== config_default_value && exchangeCard.find("#exchange_api-key").length > 0){
const apiKey = source.attr("id") === "exchange_api-key" ? newValue : exchangeCard.find("#exchange_api-key").editable('getValue', true).trim();
const apiSecret = source.attr("id") === "exchange_api-secret" ? newValue : exchangeCard.find("#exchange_api-secret").editable('getValue', true).trim();
const apiPassword = source.attr("id") === "exchange_api-password" ? newValue : exchangeCard.find("#exchange_api-password").editable('getValue', true).trim();
Expand Down
27 changes: 19 additions & 8 deletions Services/Interfaces/web_interface/static/js/common/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
$(document).ready(function() {

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

const getUserDetails = () => {
if (_USER_DETAILS.email === ""){
// do not erase email if unset
delete _USER_DETAILS.email;
}
return _USER_DETAILS
}

const updateUserDetails = () => {
posthog.capture(
getUserEmail(),
event='update_user_details',
'up_user_details',
properties={
'$set': getUserDetails(),
}
Expand All @@ -21,11 +24,19 @@ $(document).ready(function() {

const shouldUpdateUserDetails = () => {
const currentProperties = posthog.get_property('$stored_person_properties');
return (
getUserEmail() !== ""
&& isDefined(currentProperties)
&& JSON.stringify(currentProperties) !== JSON.stringify(getUserDetails())
)
if(currentProperties === undefined){
return true;
}
if(isDefined(currentProperties)){
const currentDetails = getUserDetails();
if(currentDetails.email === undefined){
// compare without email (otherwise result is always different as no email is currently set)
const localProperties = JSON.parse(JSON.stringify(currentProperties));
delete localProperties.email
return JSON.stringify(localProperties) !== JSON.stringify(getUserDetails());
}
}
return JSON.stringify(currentProperties) !== JSON.stringify(getUserDetails());
}

const shouldReset = (newEmail) => {
Expand Down
2 changes: 1 addition & 1 deletion Services/Interfaces/web_interface/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{% 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',
posthog.init('{{PH_TRACKING_ID}}',{api_host:'https://eu.i.posthog.com', person_profiles: 'always'
})
</script>
{% endif %}
Expand Down