Display contact widget only for customers logged in the customer portal

Some of our customers wish to display live chat button or other contact widget in the Customer Portal only for customers, which previously logged in into the portal. This is a very easy task - please find the instructions below.

First of all we will need to prepare the first part of the code which we will be using to check if customer is logged in. We will be checking that via variable {$userLogged} saved in the parameter userLogged.

Please navigate into the Customer portal > Settings > Customize design > Design > Own HTML > Footer HTML

Here you can use following code snippet which will be cooperating with the contact widget integration code.

Footer HTML:

<script>
var userLogged='{$userLogged}';
</script>

The second step will be editing the contact widget integration code where we add a condition to review if customer is logged in. We will be doing that in Customer portal > Settings > Customize design > Tracking codes > Before </BODY>

Here is the code snippet to use. Pleas replace the YOURDOMAIN.ladesk.com with the your URL of your LiveAgent account and xxxxxxxx with the ID of your contact widget from the original integration code.

Before </BODY>:

<script type="text/javascript">
if(userLogged!=''){
(function(d, src, c) { var t=d.scripts[d.scripts.length - 1],s=d.createElement('script');s.id='la_x2s6df8d';s.async=true;s.src=src;s.onload=s.onreadystatechange=function(){var rs=this.readyState;if(rs&&(rs!='complete')&&(rs!='loaded')){return;}c(this);};t.parentElement.insertBefore(s,t.nextSibling);})(document,
'https://YOURDOMAIN.ladesk.com/scripts/track.js',
function(e){ LiveAgent.createButton('xxxxxxxx', e); });
}
</script>

Once you save your work, you are done. Feel free to check out customer portal and see contact widget only once you log in into the portal.