-
-
Save adammatthews/578bb67632b41960e7f1 to your computer and use it in GitHub Desktop.
Intercom.io Magento CE Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* /app/design/frontend/default/your_theme/template/page/intercom-io.phtml | |
*/ | |
// Settings for the intercom.io app. | |
// Thanks to http://stackoverflow.com/a/14092378/1916670 (http://stackoverflow.com/users/452902/b4nz41) for this. | |
function convertMysqlDateTimeToUnixTimeStamp($date) { | |
$yr=strval(substr($date,0,4)); | |
$mo=strval(substr($date,5,2)); | |
$da=strval(substr($date,8,2)); | |
$hr=strval(substr($date,11,2)); | |
$mi=strval(substr($date,14,2)); | |
$se=strval(substr($date,17,2)); | |
return mktime($hr,$mi,$se,$mo,$da,$yr); | |
} | |
if( $this->helper('customer')->isLoggedIn() ): ?> | |
<?php $customer = Mage::helper('customer')->getCustomer()->getData(); ?> | |
<script id="IntercomSettingsScriptTag"> | |
var intercomSettings = { | |
app_id: 'ua6uk2qd', | |
email: "<?php echo $customer['email']; ?>", | |
name: "<?php echo $customer['firstname'] . ' ' . $customer['lastname']; ?>", | |
user_id: "<?php echo $customer['entity_id']; ?>", | |
created_at: "<?php echo convertMysqlDateTimetoUnixTimeStamp($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