Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hooking onto successful messages


  • adamt19
    Participant

    @adamt19

    I’m trying to attach some event trackers to messaging events, such as new messages and messages which are replies.

    Is it possible to do this without hacking the core file bp-messages-actions and messages_action_conversation?

    I’m using mixpanel and can track the events by dropping in this js, e.g.
    <script>mixpanel.track(‘Sent message’, array(‘Type’ => ‘Reply’));</script>

Viewing 4 replies - 1 through 4 (of 4 total)

  • adamt19
    Participant

    @adamt19

    messages_message_sent seems to work. So I guess the follow up question is how to check:

    is the message updating an existing thread *where other members have also submitted messages*, OR
    is the message a new-message (or is the person simply sending a second message after not receiving a reply?)

    I’m hoping to use that information to send additional data about the message sent event (new vs reply..)

    As always, will post my steps if I figure it out on my own 😉

    add_action( 'messages_message_sent', 'mm_mp_message_sent', 10 );
    
    function mm_mp_message_sent() {	 
    	$mp = Mixpanel::getInstance("xxxxxxxxxxxxxxxxx");
    	global $bp;
    	$mp->identify($bp->loggedin_user->id);
    	$mp->track("Sent message");
    }

    shanebp
    Moderator

    @shanebp

    Look at BP_Messages_Message class in bp-messages-classes.php

    Try using the messages_message_before_save hook

    function mm_mp_message_sent( $message ) {	 
    	$mp = Mixpanel::getInstance("xxxxxxxxxxxxxxxxx");
    	$mp->identify( bp_loggedin_user_id() );
            if ( empty( $message->thread_id ) ) 
       	   $mp->track("new message");
            else
       	   $mp->track("reply message");
    }
    add_action('messages_message_before_save', 'mm_mp_message_sent', 1, 1);

    adamt19
    Participant

    @adamt19

    Thanks @shanebp

    Attaching mixpanel analytics to buddypress activity on an active site is wildly entertaining.

    I’m trying to figure out how to isolate “Viewed Single Message”, since the user is redirected to the single-message view after they send the initial message.

    Right now composing a message fire both the “Sent message” and “Viewed message” events.

    In BP is there a way to capture whether a user is viewing a message vs. simply being redirected to their message? I was thinking of just checking for POST data.. would need to work with the ajaxy replies as well.


    shanebp
    Moderator

    @shanebp

    My guess is that there is some way to determine if the message being viewed was created by the same user_id as bp_loggedin_user_id()

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hooking onto successful messages’ is closed to new replies.
Skip to toolbar