Skip to content

Instantly share code, notes, and snippets.

@thewheat
Created June 4, 2017 15:24
Show Gist options
  • Select an option

  • Save thewheat/e5672529c4453a2f014168cb5a2c8447 to your computer and use it in GitHub Desktop.

Select an option

Save thewheat/e5672529c4453a2f014168cb5a2c8447 to your computer and use it in GitHub Desktop.
Intercom integration with Joomla. Simple integration that just modifies the index.php of your current template. Add the following code at the bottom of your current index.php file
<?php
////////////////////////////////////////////////////////////////////////////////////////////////
// Intercom integration
////////////////////////////////////////////////////////////////////////////////////////////////
// - Supports logged out users / visitors
// - Supports logged in users and has logout as well (NOTE: customise logout behaviour based on your theme)
//----------------------------------------------------------------------------------------------
// IMPORTANT
// - Customise logout behaviour based on your theme (used "protostar" theme on a standard install of Joomla! 3.7.2 Stable [ Amani ] 22-May-2017 09:46 GMT as a test)
// - Unsure how best to santize PHP code so using addslashes in this instance. Do comment if there is a better way (did not want to use htmlentities as would want to keep raw values)
//----------------------------------------------------------------------------------------------
// - Doc resources
// - Logged out snippet: https://docs.intercom.com/install-on-your-product-or-site/quick-install/install-intercom-on-your-website-for-logged-out-visitors
// - Logged in snippet: https://docs.intercom.io/install-on-your-product-or-site/install-intercom-on-your-web-app
// - Logging out: https://docs.intercom.com/faqs-and-troubleshooting/your-users-and-leads-data-in-intercom/how-do-i-end-a-session
// - Add any other custom attributes as you see fit https://docs.intercom.com/configure-intercom-for-your-product-or-site/customize-intercom-to-be-about-your-users/send-custom-user-attributes-to-intercom
////////////////////////////////////////////////////////////////////////////////////////////////
$APP_ID = "YOUR_APP_ID";
$user = JFactory::getUser();// get current logged in user details
?>
<script>
// logout of Intercom on logging out of Joomla: modify according to your theme
jQuery(document).ready(function(){
jQuery("body").on("click", ".logout button", function(){Intercom("shutdown"); });
});
<?php if ($user->guest) : ?>
window.intercomSettings = {
app_id: "<?php echo $APP_ID ?>"
};
<?php else : ?>
// include user_hash attribute for identity verification https://docs.intercom.com/configure-intercom-for-your-product-or-site/staying-secure/enable-identity-verification-on-your-web-product
window.intercomSettings = {
app_id: "<?php echo $APP_ID ?>",
email: "<?php echo addslashes($user->email) ?>",
user_id: "<?php echo $user->id ?>",
user_hash: "<?php echo hash_hmac('sha256', $user->id, 'YOUR_SECRET_KEY') ?>",
username: "<?php echo addslashes($user->username) ?>",
name: "<?php echo addslashes($user->name) ?>",
created_at: <?php echo JHtml::_('date', $user->registerDate, 'U') ?>
};
<?php endif; ?>
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function") {ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args) {i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/<?php echo $APP_ID ?>';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent) {w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment