WordPress.org

Ready to get started?Download WordPress

Forums

Intercom for WordPress
[resolved] Custom Data (3 posts)

  1. rrichardson
    Member
    Posted 1 year ago #

    How do I enter my own custom data from my site - intercom shows this

    window.intercomSettings = {
    ...
    // TODO: Add any extra data you want in Intercom to your intercomSettings
    'avatar_set' : true,
    'friend_count' : 32,
    app_id: '860bc89a47d99dd97b5b3abb7e846ee53d79837f'
    }

    But using the plugin, how can I do that?

    http://wordpress.org/extend/plugins/intercom-for-wordpress/

  2. Simon Blackbourn
    Member
    Plugin Author

    Posted 1 year ago #

    There is a filter called ll_intercom_custom_data (see line 224) which allows you to filter the $custom array.

    So for example if you store the user's country in the usermeta table, you could add something like this to your functions.php file:

    add_filter( 'll_intercom_custom_data', 'my_intercom_custom_data' );
    
    function my_intercom_custom_data( $custom ) {
    
        $user_id  = get_current_user_id();
        $country  = get_user_meta( $user_id, 'country', true );
        $custom[] = '"Country":"' . $country . '"';
    
        return $custom;
    
    }

    If you're not familiar with WordPress filters, see this page in the Codex.

    The important thing is the format of the elements in the $custom array:

    • For strings it should be "key":"value" (note the two sets of double quotes).
    • For integers it should be "key":value (only one set of quotes).
  3. Simon Blackbourn
    Member
    Plugin Author

    Posted 11 months ago #

    Just to let you know that in the new version of Intercom for WordPress the ll_intercom_custom_data filter has changed slightly, due to a change in the Intercom API.

    It's now a straightforward array of key/value pairs, there's no need to insert colons and quotes. Here's how you should now do the above code:

    add_filter( 'll_intercom_custom_data', 'my_intercom_data' );
    
    function my_intercom_data( $custom ) {
    
    	$user_id = get_current_user_id();
    
    	if ( $country = get_user_meta( $user_id, 'country', true ) ) {
    		$custom['Country'] = $country;
    	}
    
    	return $custom;
    
    }

    Sorry it's no longer backwards compatible, but I had to make this change to ensure the plugin continues to work in the future.

    Simon

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.