• Hi,
    I would like to use this plugin to get users data from a Gender and Birthday field that I have created in BuddyPress for use in Google Tag Manager or GA4.

    If it is possible, could someone please tell me how to do this?

    Thank you in advance for any help you can provide ??

    Cheers,
    Spencer

Viewing 1 replies (of 1 total)
  • Plugin Author Thomas Geiger

    (@duracelltomi)

    You could try a custom code like this to pull gender and birthday data and then hook into the gtm4wp_compile_datalayer filter to put this into the data layer:

    // Make sure BuddyPress is active
    if ( function_exists( 'bp_is_active' ) && bp_is_active( 'xprofile' ) ) {
    
    // Add an action to retrieve user data when a user profile is displayed
    add_action( 'bp_template_content', 'custom_display_user_data' );
    
    function custom_display_user_data() {
        // Get the displayed user's ID
        $user_id = bp_displayed_user_id();
    
        // Get user's profile field data
        $gender = xprofile_get_field_data( 'Gender', $user_id );
        $birthday = xprofile_get_field_data( 'Birthday', $user_id );
    }
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Get users data from BudyPress?’ is closed to new replies.