How to Monetize Chrome Extension by Injecting Ads in the Browser?


Monetizing on Chrome Extension isn’t easy e.g. You can’t put Adsense or other web-pages Ads easily in the Chrome extension because most third party ads providers will not let you put ads on Chrome popups which are not a proper web page (adsense needs to match ads base on the current page content).

You could, however, easily put a text link/image (e.g. affiliate), but that is static (and won’t change). Chrome extensions will not allow external scripts in the main popup html so the only way to display ads via Chrome Extension is to inject ads in the browser.

How to Inject Ads in the browser via Chrome Extension?

The first step is to add the following into the manifest.json of your chrome extension:

"content_scripts": [ { 
 "matches" : [ 
   "http://*/*", "https://*/*" 
 ], 
 "js" : [ "js/ads.js" ], 
 "run_at" : "document_idle", 
 "all_frames" : false 
}]

Above assumes that you put the ads.js code in the folder js. Next, the content of js/ads.js is:

1
2
3
4
5
(function(){
  var s = document.createElement('script'); 
  s.src = '//helloacm.com/ads.js';  // the third party external JS ads code.
  document.body.appendChild(s); 
})();
(function(){
  var s = document.createElement('script'); 
  s.src = '//helloacm.com/ads.js';  // the third party external JS ads code.
  document.body.appendChild(s); 
})();

It works by executing the Javascript code on document_idle (which is between document_end and document_start), then the Javascript code loads/injects the third party ads code in the current page.

However, I’d like to mention that: as it injects ads code in the browsers, which is bad for user’s experience. Especially that Popups are shown and very intrusive to users.

Most users will remove the extension if found ads injected in the browser. Click To Tweet

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
377 words
Last Post: How to Automatically Post One Blog Post to Social Networks? The Universal Solution with IFTTT and Crontab
Next Post: How to Load Balance Requests Over Several API Servers?

The Permanent URL is: How to Monetize Chrome Extension by Injecting Ads in the Browser?

4 Comments

  1. Max
  2. Yahoo Search Partner

Leave a Reply