• Resolved tango15mk

    (@tango15mk)


    Hi,

    I am adding Google analytics to my site at the moment running User Registration plugin.

    I would like to add event tracking when a user verifies their account via email and also when a user logs in, are there any hooks/actions at those points that I could hook into to add the js event tracking code?

    Thanks
    Gary

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support sanjuacharya77

    (@sanjuacharya77)

    Hi @tango15mk,

    we are extremely sorry for the delayed response.

    Yes, there are hooks that you can use to perform tasks after email verification and when user logs in. In order to track an event when a user verifies their account via email, you can use the action hook ‘user_registration_check_token_complete’ as following:

    add_action( 'user_registration_check_token_complete', 'ur_track_user_email_confirmation', 10, 2 );
    function ur_track_user_email_confirmation( $user_id, $user_reg_successful ) {
        // $user_reg_successful is either true or false. If it is false then the user's 
          email is not verified yet.
        if( $user_reg_successful === true ) {
            //Use your code here to track event
        }
    }

    In order to track an event when a user logs in, you can use the filter ‘user_registration_login_redirect’ as following:

    add_filter( 'user_registration_login_redirect', 'ur_track_user_login_session', 10, 2 );
    function ur_track_user_login_session( $redirect, $user ) {
        // Use your code here to track event
    
        // The $redirect parameter expects an url to be returned by this filter.
        return $redirect;
    }

    We are hopeful that this helps to meet your requirements. If you have any further queries, do let us know, and we will get back to you.

    Regards,
    WPEverest Support Team

    Thread Starter tango15mk

    (@tango15mk)

    Hi! Thanks for the reply.

    This is the code I have implemented:

    // Send Google Event Tracking On User Login
    add_filter( 'user_registration_login_redirect', 'ur_track_user_login_session', 10, 2 );
    function ur_track_user_login_session($redirect,$user){
        userActivity::add_new_user_activity(null,'Account','Logged In');
        // Use your code here to track event ?>
        <script>ga('create', 'UA-XXXXXX', 'auto');ga('send', 'event','Account','Logged In');</script>
        <?php // The $redirect parameter expects an url to be returned by this filter.
        return $redirect;
    }

    I have replace my Google analytics code with XXXX for the purpose of posting here.

    My own custom site tracking works fine ‘userActivity::add_new_user_activity’ so I know the hook is working, unfortunately however the Event send to Google analytics is not working?

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List of registration / hooks?’ is closed to new replies.