AvantLink HTTPS Link-Chain Fixer

I’m working on a script to modify all AvantLink Affiliate tracking links on your site to fix some of the known issues in switching to HTTPS. The AvantLink HTTPS Link-Chain Fixer script changes two things:

  • The URL to AvantLink, and
  • The link to the Merchant landing page.

The script has a built in 1 second delay to give AvantLink scripts like ALE time to do their thing first. You can see the script in action here.

* If any of your merchants do not support HTTPS do not use this script.
* This script requires jQuery to run.
* No Warranty. Use at your own risk.  

jQuery(document).ready(function(){
    function AvantLinkHTTPSLinkChainFixer(){
    /*kimballrexford.com/tag/avantlink*/
    /*version: 0.1e*/
    console.log("AvantLink HTTPS Link-Chain Fixer start:");
    jQuery('a[href*="avantlink"]').each(function(index) {
        index++;
        /* affiliate tracking link fix */
        jQuery(this).attr("href", jQuery(this).attr("href").replace("http:", "https:"));
        /* merchant link fix */
        jQuery(this).attr("href", jQuery(this).attr("href").replace("url=http%", "url=https%"));
        /* optional: add rel nofollow ? */
        jQuery(this).attr('rel','nofollow');
        /* optional: add style to help in debugging ? */
        // jQuery(this).attr('style','background-color:yellow;');
        console.log(index + ") Fixer: " + jQuery(this).attr("href"));        
    });
    console.log("AvantLink HTTPS Link-Chain Fixer done:");
    }
    /* optional: script delay: 1000 = 1 second */
    setTimeout(AvantLinkHTTPSLinkChainFixer, 1000);
});    

AvantLink HTTPS Link-Chain Fixer Options

jQuery(this).attr('rel','nofollow'); adds ref=nofollow to the affiliate links,
console.log("..."); lists the ads for you review in the javascript console. Both of these are optional. You can delete them or comment them out. If your site does not load affiliate ads via javascript you can remove setTimeout and just call AvantLinkHTTPSLinkChainFixer(); (or change 1000 to 0)

jQuery(this).attr('style','background-color:yellow;'); is in there so you see which ads are reviewed by the script. Use it to help you debug timing issues.

Here are the most common link-chain scenarios and what the script will repair.

Before Your Site AvantLink Merchant Landing Page After
OK HTTP HTTP HTTP OK
OK HTTP HTTPS HTTPS OK
OK HTTPS HTTPS HTTPS OK
FAIL? HTTP HTTP* HTTPS * Corrected
FAIL HTTP HTTPS HTTP* * Corrected
FAIL HTTPS HTTP* HTTP* * Corrected
FAIL HTTPS HTTPS HTTP* * Corrected

Published by

Profile photo of Kimball

Kimball

Kimball is a website designer and developer in Goffstown, NH.

Leave a Reply

Your email address will not be published. Required fields are marked *