$ zopim is undefined
Reading the Zopim documentation (aka Zendesk Chat):
API calls must be inserted after the Live Chat script and placed in $ zopim (function () {...})
So I have a Zopim script in head
the HTML part:
<script>/*<![CDATA[*/window.zEmbed||function(e,t){ ... }("https://...);
/*]]>*/</script>
Then I added this at the end of the HTML document:
$zopim(function() {
$zopim.livechat.setName('Logged in name');
$zopim.livechat.setEmail('user@somewhere.com');
});
And the console says:
$ zopim is undefined
I think I followed the instructions correctly . What did I miss?
source to share
I found a better solution (after submitting a support request)
zE(function() {
$zopim(function() {
$zopim.livechat.setName("{{\Auth::user()->name}}");
$zopim.livechat.setEmail("{{\Auth::user()->email}}");
});
});
I used Zendesk chat code on Zendesk support, so I need to add the Ze function to make it work using the API.
Edit : Check out the interesting comment from Jay Hewitt as well as his answer to this question .
source to share
This will be a loop waiting for $ zopim and $ zopim.livechat to load. Once they are loaded, it will stop looping.
var waitForZopim = setInterval(function () {
if (window.$zopim === undefined || window.$zopim.livechat === undefined) {
return;
}
$zopim(function() {
$zopim.livechat.setName("{{\Auth::user()->name}}");
$zopim.livechat.setEmail("{{\Auth::user()->email}}");
});
clearInterval(waitForZopim);
}, 100);
source to share