Browser Detection for Firefox and Google AdSense Button

Recently Google announced Referral program for Firefox and AdSense under its AdSense advertising programme.

Let us join hands with Google to spread Firefox browser and to end Internet Explorer monopoly!


Adding a referral button to your website enables you to generate additional earnings by directing users to download or sign up for products such as AdSense.

When a user downloads and installs Firefox through your referral, Google credit your account with up to $1.

When a publisher (website) that signed up for AdSense through your referral earns their initial $100 and is eligible for payout, Google credit your account with $100.

If you do not have an AdSense account, click on the button above to sign-up.

You can see a button on the sidebar menu of this blog too. When the visitor is already using Firefox to browse your website, it is not good to advertise for Firefox again. So I added a few lines of JavaScript code to detect the current browser and display the ad button accordingly. If the browser is Firefox, it displays the Google AdSense button, otherwise displays Firefox button. Very simple.

After you sign up, replace the google_cpa_choice line with the following lines of code, and change google_cpa_choice value accordingly. That’s it!smiling

var ua = navigator.userAgent.toLowerCase();
var isFirefox = (ua.indexOf('firefox/') != -1);
if (isFirefox) {
  google_cpa_choice = "cpa-for-AdSense";
} else {
  google_cpa_choice = "cpa-for-FireFix";


  1. i do not this so. eula is more of saying that you should not manipulate the results returned, hiding part of the display, etc.

  2. I don’t know – isn’t this editing the code? I understand that google has a line in the EULA for adsense users saying that they should not edit the given code.
    They may let this one pass though.

  3. Sree,
    Good to know that you are a FireFox user. I have been a great fan of FF since an year and thinks that it is one of the best things that has happened since man invented fire.
    Just now ended the MS monopoly on my friend’s laptop by downloading FF. As explorer was tightly integrated with the OS, he got both his OS and browser screwed because of some malicious script.
    Long live open source…

Leave a Reply

Your email address will not be published.