• Resolved sankana

    (@sankana)


    Hi, how do I make my affiliate link have a user name and not an id? so dom.com?aff=name

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author iova.mihai

    (@iovamihai)

    Hey @sankana,

    Thank you for reaching out! Out of the box, this is not possible. Tracking is done via the affiliate’s unique ID.

    Even so, with the following custom code, you can enable tracking via the user’s username. Please note, this is not the affiliate’s first name or last name or a combination of these, but the username the affiliate has selected for their user account.

    function slicewp_custom_track_visit_by_user_login( $affiliate, $query_arg ) {
    
    	// Return if we have an affiliate
    	if ( ! is_null( $affiliate ) ) {
    		return $affiliate;
    	}
    
    	$user = get_user_by( 'login', sanitize_text_field( $query_arg ) );
    	
    	if ( ! $user ) {
    		return $affiliate;
    	}
    	
    	return slicewp_get_affiliate_by_user_id( $user->ID );
    
    }
    add_filter( 'slicewp_tracking_get_affiliate_by_query_arg', 'slicewp_custom_track_visit_by_user_login', 25, 2 );
    
    
    function slicewp_custom_affiliate_url_referral_query_arg_value_user_login( $query_arg_value, $affiliate_id, $format ) {
    
    	$affiliate = slicewp_get_affiliate( $affiliate_id );
    	
    	if ( is_null( $affiliate ) ) {
    		return $query_arg_value;
    	}
    	
    	$user = get_userdata( absint( $affiliate->get( 'user_id' ) ) );
    	
    	if ( ! $user ) {
    		return $query_arg_value;
    	}
    	
    	return $user->user_login;
    
    }
    add_filter( 'slicewp_affiliate_url_referral_query_arg_value', 'slicewp_custom_affiliate_url_referral_query_arg_value_user_login', 25, 3 );

    Please copy the code and add it to your website. If you’re not sure how to add code snippets to your site, you can use the Code Snippets plugin (https://www.ads-software.com/plugins/code-snippets/).

    Once you’ve added the code to your website, you’ll notice that the referral link from the affiliate account is now showing with the username, instead of the affiliate ID.

    Also, using the new referral link should properly track the visit back to the correct affiliate.

    Please try it out and let me know how it goes.

    Thank you and best wishes,

    Mihai

    Thread Starter sankana

    (@sankana)

    It worked very well, thank you very much

    Plugin Author iova.mihai

    (@iovamihai)

    Hey @sankana,

    I’m happy to hear it worked nicely! Thank you for letting me know!

    Wishing you a lovely day ahead!

    Mihai

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘url affiliate name’ is closed to new replies.