Chatwoot/app/views/widget_tests/index.html.erb
Fayaz Ahmed 0a08e1ffc0
feat: Adds async and defer attributes to chatwoot script tag (#2890)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
2021-08-26 19:51:10 +05:30

49 lines
1.1 KiB
Text

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<%
user_id = 1
user_hash = OpenSSL::HMAC.hexdigest(
'sha256',
@web_widget.hmac_token,
user_id.to_s
)
%>
<script>
window.chatwootSettings = {
hideMessageBubble: false,
position: 'left',
locale: 'en',
type: 'expanded_bubble',
showPopoutButton: true,
};
(function(d,t) {
var BASE_URL = '';
var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src= BASE_URL + "/packs/js/sdk.js";
g.defer = true;
g.async = true;
s.parentNode.insertBefore(g,s);
g.onload=function(){
window.chatwootSDK.run({
websiteToken: '<%= @web_widget.website_token %>',
baseUrl: BASE_URL
})
}
})(document,"script");
window.addEventListener('chatwoot:ready', function() {
console.log(window.$chatwoot);
if (window.location.search.includes('setUser')) {
window.$chatwoot.setUser('<%= user_id %>', {
identifier_hash: '<%= user_hash %>',
email: 'jane@example.com',
name: 'Jane Doe',
phone_number: ''
});
}
})
</script>