Our premium plugin syncs a tonne of valuable information from WooCommerce to Intercom. But each store isn’t created equal and we knew that some store owners would want to sync unique data into Intercom.
This document runs over a few ways you can sync across custom attributes into Intercom, but before we dive into the ‘how to’, let’s recap on some of the ways data can be stored under a Users’ profile in Intercom.
Essentially a User profile is made up of attributes, events and tags.
- Attributes – unique data fields.
eg: Name, Phone Number, Order Count, Total Spend
Can filter Users based on their data.[space] - Events – possibly recurring data fields that can also contain meta data.
eg: Added Item to Cart, Changed Billing Address, Payment Completed.
Can filter Users based on when they last/first occurred and how many times they occurred, but not on event meta data. [space] - Tags – binary data fields that are either there or not.
eg: Active Subscriber, Product Title Names.
Can filter Users based on whether they’re tagged or not.[space]
We’ve found that data that is unique to a user, not to an order or form entry, is best often best saved as an attribute in Intercom; so we’re going to look into how we’d create/update a custom attribute in Intercom based on a user_meta field in WordPress (as that’s how most good plugins save global values unique to each user/customer).
Let’s assume your site adds a custom field (meta data) to the user table called ‘prefered_shirt_size’.
Our plugin uses 3 mechanisms for syncing content into Intercom. The first is via the Chat Widget initialisation code on the bottom of any front-end page, the second is via the API doing unique calls to specific functions, and the third is via the Bulk Sync module.
We’re going to focus on the first and third in this tutorial, as they cover the most general use-cases.
The following code is provided as a guide and is not guaranteed to work out-of-the-box and isn’t covered by our general support, but we’ll always do our best to help if time and resources permit.
function ektgn_footer_custom_attribute( $attributes_array, $user_id ) { $attribute_value = get_user_meta($user_id, 'prefered_shirt_size', true); if ( !empty( $attribute_value ) ){ $attributes_array['tshirt_size'] = $attribute_value; } return $attributes_array; } add_filter( 'ewi_footer_js_attribs', 'ektgn_footer_custom_attribute', 99, 2 ); add_filter( 'ewi_bulk_sync_attribs', 'ektgn_footer_custom_attribute', 99, 2 );
What the code snippet does is add the same callback function to both the ewi_footer_js_attribs and the ewi_bulk_sync_attribs filters.
The first filter triggers on the footer of every page for logged in users, and the second is used for the bulk sync module
It then checks for a custom field for the queried user, and if it exists adds the value to the array that will be sent over to Intercom. The key is the custom attribute name.
Intercom’s system then handles the calls and non-destructively adds/updates the attributes to the users profile.
If you need any help with the code, or the above is over your head, we’d suggest checking out our eWI Attributes addon which is a highly affordable customisation service in which we can help you setup up to 10 custom attributes.