Replace affiliate link with a Sovrn link
While Datafeedr does not officially support Sovrn (formerly VigLink), if you want to replace your affiliate links with a Sovrn link, here's the code to do so.
Warning
There are limitations to this method. Not all products contain the necessary data to redirect to Sovrn. If the necessary data is not available, the affiliate network affiliate link will be returned instead. Therefore it's a good idea to enter your affiliate ID for all networks just in case.
This works best with most ( but not all) products from the following affiliate networks:
2Performant, ADCELL, Admitad, AdRecord, Adtraction, AWIN, Belboon, BettyMills, ClixGalore, Commission Junction, Digital Advisor, Effiliation, Impact, LinkConnector, Rakuten, Optimise, Partnerize, Partner-ads, PepperJam, Profitshare, The Affiliate Gateway, TradeDoubler, TradeTracker & Webgains.
Pro Tip
If you are using the Datafeedr Product Sets plugin and you only want to import products into your site which work with Sovrn, then you should use the "Has Direct URL" filter and set the filter value to "yes".
Let's begin!
- 1
-
Create a custom plugin
If you haven't done so already, create a custom plugin .
- 2
-
Add custom code
Add the following custom code to your custom plugin:
/** * Replace your affiliate links with a Sovrn link. * * There are limitations to this method. Not all products contain the necessary data to * redirect to Sovrn. If the necessary data is not available, the affiliate network * affiliate link will be returned instead. Therefore, it's a good idea to enter your * affiliate ID for all networks just in case here WordPress Admin Area >Datafeedr API > Networks * * This works best with most (but not all) products from the following affiliate networks: * * 2Performant, ADCELL, Admitad, AdRecord, Adtraction, AWIN, Belboon, BettyMills, ClixGalore, * Commission Junction, Digital Advisor, Effiliation, Impact, LinkConnector, Rakuten, Optimise, * Partnerize, Partner-ads, PepperJam, Profitshare, The Affiliate Gateway, TradeDoubler, * TradeTracker & Webgains. * * To use this code you must add your Sovrn API key at the top of this function. * * Replace 123456789abcde with your Sovrn API key. * * Your Sovrn API key can be found on your Sovrn account page. * * @param string $url Description. * @param array $product An array of the current Datafeedr product's information. * @param string $affiliate_id Affiliate ID for current product. * * @return string URL. */ add_filter( 'dfrapi_before_affiliate_id_insertion', function ( $url, $product, $affiliate_id ) { // Replace 123456789abcde with YOUR unique Sovrn API key. $sovrn_key = '123456789abcde'; /* Stop Editing */ $viglink_url = 'http://redirect.viglink.com/'; $key = 'direct_url'; if ( ! isset( $product[ $key ] ) ) { return $url; } $direct_url = urlencode( $product[ $key ] ); return add_query_arg( [ 'u' => $direct_url, 'key' => $sovrn_key ], $viglink_url ); }, 20, 3 );
- 3
-
Add your Sovrn API key
Replace
123456789abcde
with your Sovrn API key. Your Sovrn API key can be found on your Sites dashboard page (click the key icon in the Actions column). - 4
-
Save
Save your custom plugin file.
Now any product which has the required data for being converted into a Sovrn link will be converted.