Affiliate Links','manage_options','aff_lnk_options','aff_lnk_options'); } function aff_lnk_options() { load_plugin_textdomain('link-tracker-list',false,basename(dirname(__FILE__))); if (!current_user_can('manage_options')) wp_die(__('You do not have sufficient permissions to access this page.','link-tracker-list')); echo '

Advanced Affiliate Link Tracker

' .'
' .''; settings_fields("aff_lnk_admin_group"); $red=get_option('aff_lnk'); echo '
' .'
Redirect from URLRedirect to URLTracking tagHits
' .'

' .'
Instructions

How to use the plugin

  1. Enter the URL you want to redirect FROM in the LEFT input box.
  2. Enter the URL you want to redirect TO in the RIGHT input box.
  3. Select the tracking tag that your affiliate network uses from the dropdown menu.

How it works

When a user visits your site, a cookie is created to capture URL parameters (standard UTM tags).

Information captured in the cookie will be appended to your outbound URL, with the corresponding tracking tag of your choice.

If your URL contains other URL parameters, they will be unaffected. A preceding "?" or "&" will be added to tags automatically as needed.

If a referrer is set, it will be included. If no referrer is set, the landing page will be inserted instead.

Every time a redirect is triggered, the hit counter will increase by one. You can reset the counter by exporting, removing the count and re-importing.

Standard UTM tags

These are the standard UTM tags and their typical usage (plus examples). Include any or all of these UTM tags in your inbound URLs to enable UTM tag tracking.

    utm_source = The specific source (Google, Facebook, example.com)

    utm_medium = The type of traffic (paid, organic, social, etc.)

    utm_campaign = The specific campaign (Sunglasses, Caps, etc.)

    utm_term = The specific keyword (buy sunglasses, best sunglasses, etc.)

    utm_content = The specific placement (sidebar, top, bottom, email, blog post, etc.)

Any tag that is set will be added to the cookie, and appended to the outbound affiliate link as a text string. The URL will look something like this:

https://your-affiliate-network.com/?clickref=mysource-mymedium-mycampaign-myterm-mycontent-google.com

You will now be able to see the appended information in your affiliate backend.

Importing/exporting CSV

Please note that all four fields (from URL, to URL, tag # and hit count) are required for importing, or it will assume null values.

NOTE: While no personal data is stored by this plugin, please notify your users that you are using cookies if your local legislature requires you to (and to be nice).

For testing: Use the shortcode [aff_lnk_view_cookie] to see what is stored in your current cookie. The cookie is held for 30 days. Use a private window (incognito mode) in your browser to get/create a new cookie.

Please refer to readme.txt for further information

' .'

' .'' .'
'; } function aff_lnk_validate($in) { $out=array(); $url=get_site_url(); $in=json_decode($in,true); if (is_array($in)) for ($i=0;$i1&&substr($url,-1)=='/') $url=substr($url,0,strlen($url)-1); for ($i=0;isset($red[$i]);$i++) { $tmp=explode('?',$red[$i][0]); if (strlen($tmp[0])>1&&substr($tmp[0],-1)=='/') $tmp[0]=substr($tmp[0],0,strlen($tmp[0])-1); if ($url==$tmp[0]) { $exe=true; if (count($tmp)>1) { $tmp=explode('&',$tmp[1]); foreach ($tmp as $x) if ($x) { $x=explode('=',$x); if (!isset($_GET[$x[0]])||(count($x)>1&&urldecode($_GET[$x[0]])!=urldecode($x[1]))) $exe=false; } } else if ($qry!==false) $exe=false; $aff_lnk_url = $red[$i][1]; $aff_lnk_tag = intval($red[$i][2]); $aff_lnk_string = sanitize_text_field($_COOKIE["aff_lnk_cookie"]); if ($exe) { $aff_lnk_tag_array = array( '0' => 'source', '1' => 'epi', '2' => 'sub', '3' => 'ref', '4' => 'clickref', '5' => 'subid', '6' => 'sid', '7' => 'r', '8' => 'afftrack', ); $aff_lnk_tracktag = $aff_lnk_tag_array[$aff_lnk_tag]; } if (parse_url($aff_lnk_url, PHP_URL_QUERY)) { $aff_lnk_tracktag = '&'.$aff_lnk_tracktag.'='; } else { $aff_lnk_tracktag = '?'.$aff_lnk_tracktag.'='; } $red[$i][3]++; update_option('aff_lnk',$red); wp_redirect($aff_lnk_url.$aff_lnk_tracktag.$aff_lnk_string,302); exit; } } } add_action('plugins_loaded','aff_lnk_go'); /* Adds settings link to plugin list */ add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'aff_add_plugin_page_settings_link'); function aff_add_plugin_page_settings_link( $links ) { if (current_user_can('manage_options')) { $settings = '' . __('Settings') . ''; array_unshift($links, $settings); } return $links; } /* Knead the dough and bake the cookie (if none exists) */ function aff_lnk_bake_cookie() { if (!isset($_COOKIE['aff_lnk_cookie'])) { if (isset($_SERVER['HTTP_REFERER'])) { $aff_lnk_referrer = esc_url($_SERVER['HTTP_REFERER']); } else { $aff_lnk_referrer = strtok($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], '?'); } $aff_lnk_referrer = preg_replace('#^https?://#', '', rtrim($aff_lnk_referrer,'/')); $aff_lnk_utm_array = array( 'utm_source' => sanitize_text_field($_GET["utm_source"]), 'utm_medium' => sanitize_text_field($_GET["utm_medium"]), 'utm_campaign' => sanitize_text_field($_GET["utm_campaign"]), 'utm_term' => sanitize_text_field($_GET["utm_term"]), 'utm_content' => sanitize_text_field($_GET["utm_content"]), 'http_referrer' => sanitize_text_field($aff_lnk_referrer), ); $aff_lnk_utm_array = array_filter($aff_lnk_utm_array); $aff_lnk_recipe = implode("-",$aff_lnk_utm_array); setcookie('aff_lnk_cookie',$aff_lnk_recipe,time()+60*60*24*30, '/'); /* This part lets you set and use the cookie on the same page */ if(!isset($_COOKIE['aff_lnk_cookie'])){ $_COOKIE['aff_lnk_cookie'] = sanitize_text_field($aff_lnk_recipe); } } } add_action('init', 'aff_lnk_bake_cookie'); //View cookie shortcode for testing purposes function aff_lnk_shortcode ( $atts, $content = null ) { $content = sanitize_text_field($_COOKIE["aff_lnk_cookie"]); return $content; } add_shortcode( 'aff_lnk_view_cookie', 'aff_lnk_shortcode' ); ?>