Skip to content

Instantly share code, notes, and snippets.

@larascasse
Forked from davekelly/gist:3918937
Created March 11, 2016 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larascasse/07ae7136dbf307e46601 to your computer and use it in GitHub Desktop.
Save larascasse/07ae7136dbf307e46601 to your computer and use it in GitHub Desktop.
Add Intercom.io snippet to Magento site
<?php
/*
* /app/design/frontend/default/your_theme/template/page/intercom-io.phtml
*/
// Settings for the intercom.io app.
if( $this->helper('customer')->isLoggedIn() ): ?>
<?php $customer = Mage::helper('customer')->getCustomer()->getData(); ?>
<script id="IntercomSettingsScriptTag">
var intercomSettings = {
app_id: 'your_app_id',
email: "<?php echo $customer['email']; ?>",
name: "<?php echo $customer['firstname'] . ' ' . $customer['lastname']; ?>",
user_id: "<?php echo $customer['entity_id']; ?>",
created_at: <?php echo time( $customer['created_at'] ); ?>
};
(function() {
var i=function(){i.c(arguments)};i.q=[];
i.c=function(args){i.q.push(args)};window.Intercom=i;
function async_load() {
var s = document.createElement('script');
s.type = 'text/javascript'; s.async = true;
s.src = 'https://api.intercom.io/api/js/library.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
if (window.attachEvent) {
window.attachEvent('onload', async_load);
} else {
window.addEventListener('load', async_load, false);
}
})();
</script>
<?php endif; ?>
/*
* This goes in the theme's layout/local.xml file (in the <default> section)
* - it could also go into the page.xml file...
*/
<reference name="before_body_end">
<block type="core/template" template="page/intercom-io.phtml" />
</reference>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment