Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Page and Site Features

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Hiding Affiliate Code In Browser Address Bar

As a merchant, you want to keep your affiliates happy.

If you use ClickBank (or other systems that leave the affiliate's ID in the URL of the browser's address bar), it can be obvious to the potential buyer that an affiliate link was followed.

This affects affiliates in two ways. (And it affects you, too, as some affiliates may decide not to promote your product because of that fault.)

  1. It tells the buyer an affiliate link was followed.

    The information can devalue the affiliate's recommendation and your product in the viewpoint of the buyer. The thinking is that the recommendation was made primarily for the commission, not because your product is so good.

  2. The buyer may register as an affiliate and then buy through their own link.

    This point will send affiliates away in droves. Well, the smart ones, unless they're a personal friend or the affiliate knows in advance that the product is extraordinarily good. You really don't want to be stuck with a bunch of dumb affiliates, do you?

    At first glance, an affiliate sign-up before purchase may appear to be a good thing for you, the merchant. After all, you get another affiliate on the rolls. And get a sale you perhaps would not have otherwise.

    Let me deflate that bubble.

    1. The person who signs up as an affiliate to get a discount will not promote your product. After all, they know from their own actions that people will just sign up to get a discount and bypass the affiliate.

    2. It may be a sale that otherwise would not have happened.

      In all likelihood, if the product was worth going through the trouble of signing up as an affiliate before buying, it would also have been worth the full price.

    Consider if that one sale is an acceptable trade for the potential of many sales because of happy affiliates.

  3. It looks amateurish.

    This article shows you how to remove the affiliate code in the address bar for a more professional appearance.

    A clean URL in the address bar is evidence you care about your business. It shows smart affiliates you care about them.

Affiliate codes, if embedded in the URL, generally are located somewhere after a question mark character ("?"). Examples:

http://example.com/page.html?aff=code&from=ad
http://example.com/page.html?hop=willmaster

For those types of URLs, the question mark and everything following it can be removed from the URL in the browser's address bar when the prospect arrives at the sales page.

Either PHP or JavaScript can be used.

PHP accomplishes it faster than JavaScript does.

With PHP, the redirect happens before the page ever gets to the browser. With JavaScript, the redirect happens after the page, or at least some of it, has been received by the browser.

Both versions work. They work by redirecting the browser to a clean URL of the same web page. If you can not use the PHP version, use the JavaScript.

After publication clarification:

Soon after publishing this article, we received notes from several concerned readers that the techniques in this article would prevent the affiliate from getting paid.

The following was not specifically mentioned in the article. Therefore, let me clarify: When the product page at the merchant's website is loaded into the browser, the affiliate cookie should already have been set. The URL in the browser's address bar has nothing to do with whether or not an affiliate cookie is set.

ClickBank sets the affiliate cookie at their domain before sending the browser to the merchant. All affiliate programs I've used either

  • set the cookie before the browser is redirected to the product page, or
  • set the cookie via the page headers immediately before the product page is loaded into the browser.

If uncertain, check.

Always check a new merchant's cookie setting anyway — unscrupulous merchants may put the affiliate information into the browser's address bar, as a smokescreen, without setting an affiliate cookie.

How to check cookies is beyond the scope of this short note. Find out by using key words

view cookies firefox

in a search engine (replacing "firefox" with the name of your browser).

FYI, affiliate programs that rely on affiliate information in the URL of the browser's address bar for credit information are not reliable. That's because referrer information is not reliable, not all browsers provide the info to payment gateways and there is no persistence. Cookies are a better choice in almost all implementations.

For merchants:

Because of the mental association of affiliate cookies with affiliate information embedded into the URL of the browser's address bar, some potential affiliates may be uncomfortable with a clean browser URL at the product page.

The following shows how to make a clean URL on the product page. Both PHP and JavaScript instructions are provided.

Using PHP

To use PHP, it must be a PHP web page. On most servers, the web page file name needs to end with ".php"

Because the PHP code uses header information to redirect, the code must be on the web page above anything that is published. Above the <html> tag. Above any blank lines.

Put it at the top of the page, unless other PHP codes exists on that same page that must set a cookie before the redirect happens, perhaps an affiliate-related cookie. In that case, put the PHP redirect code somewhere below the cookie setting code (but still above anything that is published on the web page, including spaces or blank lines).

Here is the PHP source code.

<?php
if(isset($_SERVER['QUERY_STRING']) and strlen($_SERVER['QUERY_STRING'])>0)
{
   header('Location: ' . $_SERVER['PHP_SELF']);
   exit;
}
?>

Paste it into the source code of your PHP web page. No edits necessary.

Using JavaScript

JavaScript can be used on any web page.

The browser needs to have JavaScript turned on. But that is usually the case. The few that don't will just have to live with a URL in the browser's address bar that contains affiliate code information.

Put the JavaScript as far up on the page as you can. Similar to when using PHP, if JavaScript on the page must set a cookie before the redirect happens, then put this JavaScript redirect code somewhere below the cookie setting code.

The sooner the browser sees the JavaScript, the sooner the redirect will happen. The sooner the redirect happens, the less time is spent needlessly rendering the page before the redirect.

Here is the JavaScript source code.

<script type="text/javascript">
if(location.search && location.search.length>0)
{ 
   document.location.href=document.URL.replace(/\?.*$/,'');
}
</script>

Paste the JavaScript into the source code as far up on the web page as you can. Have it be the first lines of the HEAD area, if possible. No edits required for the JavaScript.

Testing

Copy and paste is almost all that needs to be done. The last step is testing.

If the test fails, double-check the code you pasted into your page. And verify the page was actually uploaded to the server.

The code makes clean URLs for browsers' address bars. Uncluttered with affiliate code information.

It is more professional. It shows affiliates you care about not blatantly advertising the potential customer came from an affiliate link.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC