Skip to content

Commit

Permalink
integrate productfruits on login page (#219)
Browse files Browse the repository at this point in the history
with random username and role `anonymous`

CPCN-977
  • Loading branch information
petrjasek authored Dec 17, 2024
1 parent e32cb54 commit 8ad60fe
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions server/theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{% endblock %}

{% block layout_script %}

{% if config.PRODUCTFRUITS_WORKSPACE_CODE and auth_user %}
<script type="text/javascript">
(function(w,d,u){
Expand All @@ -38,5 +39,34 @@
},
}]);
</script>
{% elif config.PRODUCTFRUITS_WORKSPACE_CODE %}
<script type="text/javascript">
function makeid(length) {
let result = '';
let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}

let generatedUserName = localStorage.getItem('user');
if (!generatedUserName) {
generatedUserName = makeid(8);
localStorage.setItem('user', generatedUserName);
}

(function(w,d,u){
w.$productFruits=w.$productFruits||[];
w.productFruits=w.productFruits||{};w.productFruits.scrV='2';
let a=d.getElementsByTagName('head')[0];let r=d.createElement('script');r.async=1;r.src=u;a.appendChild(r);
})(window,document,'https://app.productfruits.com/static/script.js');
$productFruits.push(['init', '{{ config.PRODUCTFRUITS_WORKSPACE_CODE }}', '{{ get_locale()[:2] }}', {
username: generatedUserName,
role: 'anonymous',
}]);
</script>
{% endif %}

{% endblock %}

0 comments on commit 8ad60fe

Please sign in to comment.