3

We want to install a live chat tool onto our Magento store. The tool is from LiveChatInc.com and requires you to add their javascript snippet before the closing tag of the site.

Is this as simple as adding the code snippet to: System > Configuration > Design > HTML Head > Miscellaneous Scripts ?

There code snippet is JavaScript

3

This will probably work but it adds the script within the <head> element instead of at the end of the <body> element, which hurts the user experience because it blocks page rendering until the script has loaded.

The right way™ would be to add it to the bottom via layout XML. Add the following lines to the layout/local.xml file of your theme:

<default>
    <reference name="before_body_end">
        <block type="core/text" name="live_chat_js" after="-">
            <action method="setText"><text><![CDATA[

... ADD YOUR SNIPPET HERE ...

]]></text></action>
        </block>
    </reference>
</default>
|improve this answer|||||
1

Yes, to add a small amount of javascript you can just use the Miscellaneous Scripts box, being sure enclose your JS in if it isn't already.

Alternatively you could add this to the head.phtml file in your theme or if it needs to be loaded after all other content the footer.phtml.

|improve this answer|||||
  • When you say enclosed, what do you mean? p.s. this is their code snippet: <script type="text/javascript"> var __lc = {}; __lc.license = 1111111; (function() { var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true; lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc.com/tracking.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s); })(); </script> – user31452 Jun 25 '15 at 15:41
  • That's fine as is. By enclosed I meant that javascript needs to have the <script> tags around it in the header. The snippet there already does so you can just insert it straight in. – performadigital Jun 25 '15 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.