A Javascript tool for adding referral information to correspondent links. Supports any affiliate that just needs a parameter added to the link (Eg. http://somesite.com/product-1234/?ref={YOUR-REFERRAL-ID}). It also supports affiliate links through Commission Junction, it detects supported sites and replaces the link 'href' tag with the corresponding URL.
-
Include Scrooge.js in your
head
:<script src="js/scrooge.js"></script>
-
Configure Scrooge inside a
<script>
tag after including it:<script> Scrooge.setAffiliateId('amazon', '{YOUR-AFFILIATE-ID}') .addSite('somesite', 'ref', '{YOUR-AFFILIATE-ID}') .addCjSite('zappos', 'zappos.com', '{YOUR-AFFILIATE-ID}', '{MERCHANT-ID}'); </script>
-
You're done.
Runs Scrooge and replaces every detected affiliate URL. You don't have to manually call it this method is run when the page is loaded. You can manually trigger the replacement after a DOM manipulation to detect and replace the new links.
By default Scrooge searches for affiliate URLs in the whole document but if you want to limit the URL replacement to just the links inside an element you can use this method.
context
- String or DOM element.
// Setting the context to a particular element with the id 'article'.
Scrooge.setContext('#article');
// Setting the context to a particular DOM element.
Scrooge.setContext(window.article);
Adds an affiliate site for url detection and replacement.
key
- String, a key or id used internally by Scrooge to identify each affiliate.domain
- String, the domain that will be searched in links to add the affiliate information.parameter_name
- String, the name of the parameter that will be added to the url.affiliate_id
- String, your affiliate id.
// Adding iTunes as an affiliate
Scrooge.addSite('itunes', 'itunes.apple.com', 'affId', '{YOUR-AFFILIATE-ID}');
Adds an affiliate site that works throught the Commision Junction referral system.
key
- String, a key or id used internally by Scrooge to identify each affiliate.domain
- String, the domain that will be searched in links to add the affiliate information.affiliate_id
- String, your CJ affiliate id (PID).merchant_id
- String, the merchant link id (AID).
Removes an affiliate site by its key.
key
- String, the key for the site that will be removed.
Removes an affiliate site from Commission Junction by its key.
key
- String, the key for the site that will be removed.
-
Every method returns an instance to the Scrooge object so every method is chainable:
Scrooge.addSite().addCjSite().setAffiliateId();
-
For Commission Junction you'll need the following information:
- PID (Affiliate ID): In the cj.com admin area: Account > Web Site Settings > PID
- AID (Advertiser ID): The Advertiser/Merchant ID can be found by opening the Get Links of any active advertiser.
<script src="scrooge.js"></script>
<script>
// Setting the context to search only inside an element with a 'detect' id
Scrooge.setContext('#detect')
// Adding support for amazon.com links
.addSite('amazon', 'amazon.*', 'tag', 'httpmariec-20')
// Adding support for iTunes links
.addSite('itunes', 'itunes.apple.com', 'affId', 'TEST')
// Adding support for newegg.com through Commmission Junction
.addCjSite('newegg', 'newegg.com', '4858864', '10440897')
// Adding support for a fictitous site
.addSite('somesite', 'somesite.com', 'referral', 'YOUR-REFERRAL-ID');
</script>
<ul id="detect">
<li><a href="https://www.amazon.com/Western-Digital-Scorpio-Notebook-WD3200BEKT/dp/B001CO3EKQ/ref=sr_1_2?ie=UTF8&qid=1299021901&sr=8-2">Scorpio Black (Amazon)</a></li>
<li><a href="http://www.newegg.com/Product/Product.aspx?Item=N82E16822136831&cm_re=wd_tv_live-_-22-136-831-_-Product">WD TV Live Hub Media Center (Newegg)</a></li>
<li><a href="http://www.somesite.com/product/1234/">Dummy Site</a></li>
<li><a href="http://itunes.apple.com/us/app/isaac-newtons-gravity/id345439503?mt=8">Isaac Newton's Gravity [iTunes]</a></li>
</ul>