0

I would like to be able to automatically change links into affiliate links on my Wordpress and Mybb installation. This would help to reduce the amount of time managing links in case the code needs to be changed in the future as you know advertiser keeps changing the affiliate websites from one another.

This is my setup of bestylish.com affiliate scheme. If the url is suppose : http://www.bestylish.com/men-shoes
I need to make it this :- http://affiliates.tyroodr.com/ez/arttnpokwow/&lnkurl=http://www.bestylish.com/men-shoes%3Futm_source%3Dtyroo%26utm_medium%3Daffiliate%26utm_campaign%3D12june12_20percenteossoffer

I also need to have a http:// always before starting www.bestylish.com if its there, it ok, if its not there, then i need to add it otherwise it wont be redirected correctly.

The same Kind of thing is here : Change all website links to affiliate links automatically

But this talks about appending the code at the end only, whereas i have to append the code at the beginning too. Also this doesn't talk about adding http:// in the beginning everytime. Can anyone help me with this?

Thanks you.

Community
  • 1
  • 1
Piyush
  • 9
  • 1
  • 2

3 Answers3

0

You can use a very similar jQuery function to update your links, you can just add the new URL info before and after the current link, see below:

// attach a click even to all <a> elements
$("a").click(function() {
    addAffiliate(this);
});

// your affiliate URL and querystrig variable for redirect
var affiliateURL = "http://affiliates.tyroodr.com/ez/arttnpokwow/?lnkurl=";
// additional querystring values to append
var addQueryString = "&utm_source=tyroo&utm_medium=affiliate&utm_campaign=12june12_20percenteossoffer";

// function called when link is clicked
function addAffiliate(link) {
    // make sure this link does is not to the current site and does not contain the affiliateURL
    if ((link.href).indexOf(location.host) < 0 && (link.href).indexOf(affiliateURL) < 0){
        // update the link with the affiliateURL, the url encoded link, and the additional query string
        link.href = affiliateURL + escape(link.href) + addQueryString;
    }
    alert(link.href);
    // return true to follow the link
    return true;
}
doublesharp
  • 26,888
  • 6
  • 52
  • 73
  • Hello doublesharp, i am able to work this out. Can you show me demo here please. : http://jsfiddle.net/eK7XW/ thanks – Piyush Oct 29 '12 at 05:28
  • This won't work on jsfiddle.com since it uses the `location.hostname` to decide when to update a link, which one your site would be `www.beststylish.com` but in the test would be `jsfiddle.com`. I can say that the second example you have is incorrect, if you were on `http://beststylish.com` and clicked it the result would be `http://beststylish.com/www.beststylish.com` – doublesharp Oct 29 '12 at 15:08
0

I think you are looking for this type of work.

please visit => http://nullrefer.com/?http://freekaamaal.com/discuss/index.php

Join this forum and try to post any link in thread it will convert to affiliate link. I am also looking for this type of script but unable to figure out how it's dome.

best regards

bbpowercis

0

First of all, if the advertiser change their platform or affiliatet network they are working with probably all the links ( both real and affiliate links ) will change, so you need to do your custom thing for every merchant your promote.

I can suggest you to try to have some affiliate links cloaking/management plugin or service. You can try bit.ly to manage and cloak links, and there are many free wordpress plugins that will let you do that: http://wordpress.org/plugins/search.php?q=link+cloak&sort=

If you want something more advanced, you may have a look at: http://autoaffiliatelinks.com/

Lucian
  • 67
  • 2