{"id":805,"date":"2010-06-05T03:25:05","date_gmt":"2010-06-05T01:25:05","guid":{"rendered":"http:\/\/raftaman.net\/?p=805"},"modified":"2021-05-15T11:46:40","modified_gmt":"2021-05-15T09:46:40","slug":"inside-adsenses-show_ads-js","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=805","title":{"rendered":"Inside adsense&#8217;s show_ads.js"},"content":{"rendered":"<p>For those of you, who want to understand what goes on inside google adsense&#8217;s <code>show_ads.js<\/code>, here is the complete source code:<\/p>\n<pre class=\"brush: jscript; collapse: true; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\ngoogle_ad_url = '';\r\ngoogle_random = (new Date()).getTime();\r\ngoogle_org_error_handler = window.onerror;\r\n\r\nfunction quoted(str) {\r\n  return (str != null) ? '&quot;' + str + '&quot;' : '&quot;&quot;';\r\n}\r\n\r\nfunction google_encodeURIComponent(str) {\r\n  if (typeof(encodeURIComponent) == 'function') {\r\n    return encodeURIComponent(str);\r\n  } else {\r\n    return escape(str);\r\n  }\r\n}\r\n\r\nfunction google_write_tracker(tracker_event) {\r\n  var img_url = window.google_ad_url.replace(\/pagead\\\/ads\/, 'pagead\/imp.gif');\r\n  var img_src = img_url + '&amp;event=' + tracker_event;\r\n  var img_tag = '&lt;i' + 'mg height=&quot;1&quot; width=&quot;1&quot; border=&quot;0&quot; ' +\r\n                'src=' + quoted(img_src) +\r\n                ' \/&gt;';\r\n  document.write(img_tag);\r\n}\r\n\r\nfunction google_append_url(param, value) {\r\n  if (value) {\r\n    window.google_ad_url += '&amp;' + param + '=' + value;\r\n  }\r\n}\r\n\r\nfunction google_append_url_esc(param, value) {\r\n  if (value) {\r\n    google_append_url(param, google_encodeURIComponent(value));\r\n  }\r\n}\r\n\r\nfunction google_append_color(param, value) {\r\n  if (value &amp;&amp; typeof(value) == 'object') {\r\n    value = value&#x5B;window.google_random % value.length];\r\n  }\r\n  google_append_url('color_' + param, value);\r\n}\r\n\r\nfunction google_show_ad() {\r\n  var w = window;\r\n  w.onerror = w.google_org_error_handler;\r\n\r\n  if (w.google_num_ad_slots) {\r\n    w.google_num_ad_slots = w.google_num_ad_slots + 1;\r\n  } else {\r\n    w.google_num_ad_slots = 1;\r\n  }\r\n\r\n  if (w.google_num_ad_slots &gt; 3) {\r\n    return;\r\n  }\r\n\r\n  w.google_ad_url = 'http:\/\/pagead2.googlesyndication.com\/pagead\/ads?';\r\n  w.google_ad_client = w.google_ad_client.toLowerCase();\r\n  if (w.google_ad_client.substring(0,3) != 'ca-') {\r\n     w.google_ad_client = 'ca-' + w.google_ad_client;\r\n  }\r\n  w.google_ad_url += 'client=' + escape(w.google_ad_client) +\r\n                     '&amp;random=' + w.google_random;\r\n\r\n  google_append_url('hl', w.google_language);\r\n  if (w.google_country) {\r\n    google_append_url('gl', w.google_country);\r\n  } else {\r\n    google_append_url('gl', w.google_gl);\r\n  }\r\n  google_append_url('gr', w.google_region);\r\n  google_append_url_esc('gcs', w.google_city);\r\n  google_append_url_esc('hints', w.google_hints);\r\n  google_append_url('adsafe', w.google_safe);\r\n  google_append_url('oe', w.google_encoding);\r\n  google_append_url('lmt', w.google_last_modified_time);\r\n  google_append_url_esc('alternate_ad_url', w.google_alternate_ad_url);\r\n  google_append_url('alt_color', w.google_alternate_color);\r\n\r\n  if (w.google_skip) {\r\n    google_append_url(&quot;skip&quot;, w.google_skip);\r\n  } else if (w.google_prev_ad_formats) {\r\n    google_append_url_esc('prev_fmts', w.google_prev_ad_formats.toLowerCase());\r\n  }\r\n\r\n  if (w.google_ad_format) {\r\n    google_append_url_esc('format', w.google_ad_format.toLowerCase());\r\n    if (w.google_prev_ad_formats) {\r\n      w.google_prev_ad_formats = w.google_prev_ad_formats + ',' + w.google_ad_format;\r\n    } else {\r\n      w.google_prev_ad_formats = w.google_ad_format;\r\n    }\r\n  }\r\n\r\n  google_append_url('num_ads', w.google_max_num_ads);\r\n  google_append_url('output', w.google_ad_output);\r\n  google_append_url('adtest', w.google_adtest);\r\n  if (w.google_ad_channel) {\r\n    google_append_url_esc('channel', w.google_ad_channel.toLowerCase());\r\n  }\r\n  google_append_url_esc('url', w.google_page_url);\r\n  google_append_color('bg', w.google_color_bg);\r\n  google_append_color('text', w.google_color_text);\r\n  google_append_color('link', w.google_color_link);\r\n  google_append_color('url', w.google_color_url);\r\n  google_append_color('border', w.google_color_border);\r\n  google_append_color('line', w.google_color_line);\r\n  google_append_url('kw_type', w.google_kw_type);\r\n  google_append_url_esc('kw', w.google_kw);\r\n  google_append_url_esc('contents', w.google_contents);\r\n  google_append_url('num_radlinks', w.google_num_radlinks);\r\n  google_append_url('max_radlink_len', w.google_max_radlink_len);\r\n  google_append_url('rl_filtering', w.google_rl_filtering);\r\n  google_append_url('ad_type', w.google_ad_type);\r\n  google_append_url('image_size', w.google_image_size);\r\n  google_append_url('feedback_link', w.google_feedback);\r\n\r\n  w.google_ad_url = w.google_ad_url.substring(0, 1000);\r\n  w.google_ad_url = w.google_ad_url.replace(\/%\\w?$\/, '');\r\n\r\n  if (google_ad_output == 'js' &amp;&amp; w.google_ad_request_done) {\r\n    document.write('&lt;scr' + 'ipt language=&quot;JavaScript1.1&quot;' +\r\n                   ' src=' + quoted(google_ad_url) +\r\n                   '&gt;&lt;\/scr' + 'ipt&gt;');\r\n  } else if (google_ad_output == 'html') {\r\n    if (w.name == 'google_ads_frame') {\r\n      google_write_tracker('reboundredirect');\r\n    } else {\r\n      document.write('&lt;ifr' + 'ame' +\r\n                     ' name=&quot;google_ads_frame&quot;' +\r\n                     ' width=' + quoted(w.google_ad_width) +\r\n                     ' height=' + quoted(w.google_ad_height) +\r\n                     ' frameborder=' + quoted(w.google_ad_frameborder) +\r\n                     ' src=' + quoted(w.google_ad_url) +\r\n                     ' marginwidth=&quot;0&quot;' +\r\n                     ' marginheight=&quot;0&quot;' +\r\n                     ' vspace=&quot;0&quot;' +\r\n                     ' hspace=&quot;0&quot;' +\r\n                     ' allowtransparency=&quot;true&quot;' +\r\n                     ' scrolling=&quot;no&quot;&gt;');\r\n      google_write_tracker('noiframe');\r\n      document.write('&lt;\/ifr' + 'ame&gt;');\r\n    }\r\n  }\r\n\r\n  w.google_ad_frameborder = null;\r\n  w.google_ad_format = null;\r\n  w.google_page_url = null;\r\n  w.google_language = null;\r\n  w.google_gl = null;\r\n  w.google_country = null;\r\n  w.google_region = null;\r\n  w.google_city = null;\r\n  w.google_hints = null;\r\n  w.google_safe = null;\r\n  w.google_encoding = null;\r\n  w.google_ad_output = null;\r\n  w.google_max_num_ads = null;\r\n  w.google_ad_channel = null;\r\n  w.google_contents = null;\r\n  w.google_alternate_ad_url = null;\r\n  w.google_alternate_color = null;\r\n  w.google_color_bg = null;\r\n  w.google_color_text = null;\r\n  w.google_color_link = null;\r\n  w.google_color_url = null;\r\n  w.google_color_border = null;\r\n  w.google_color_line = null;\r\n  w.google_adtest = null;\r\n  w.google_kw_type = null;\r\n  w.google_kw = null;\r\n  w.google_num_radlinks = null;\r\n  w.google_max_radlink_len = null;\r\n  w.google_rl_filtering = null;\r\n  w.google_ad_type = null;\r\n  w.google_image_size = null;\r\n  w.google_feedback = null;\r\n  w.google_skip = null;\r\n}\r\n\r\nfunction google_error_handler(message, url, line) {\r\n  google_show_ad();\r\n  return true;\r\n}\r\n\r\nwindow.onerror = google_error_handler;\r\n\r\nif (window.google_ad_frameborder == null) {\r\n  google_ad_frameborder = 0;\r\n}\r\n\r\nif (window.google_ad_output == null) {\r\n  google_ad_output = 'html';\r\n}\r\n\r\nif (window.google_ad_format == null &amp;&amp; window.google_ad_output == 'html') {\r\n  google_ad_format = google_ad_width + 'x' + google_ad_height;\r\n}\r\n\r\nif (window.google_page_url == null) {\r\n  google_page_url = document.referrer;\r\n  if (window.top.location == document.location) {\r\n    google_page_url = document.location;\r\n    google_last_modified_time = Date.parse(document.lastModified) \/ 1000;\r\n  }\r\n}\r\ngoogle_show_ad();\r\n<\/pre>\n<p>Found on <a href=\"http:\/\/www.koders.com\/javascript\/fid736F583884B4ED35245CF576DB385E6AC876A6E1.aspx\">http:\/\/www.koders.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For those of you, who want to understand what goes on inside google adsense&#8217;s show_ads.js, here is the complete source code: google_ad_url = &#8221;; google_random = (new Date()).getTime(); google_org_error_handler = window.onerror; function quoted(str) { return (str != null) ? &#8216;&quot;&#8217; + str + &#8216;&quot;&#8217; : &#8216;&quot;&quot;&#8217;; } function google_encodeURIComponent(str) { if (typeof(encodeURIComponent) == &#8216;function&#8217;) { return encodeURIComponent(str); } else {&#8230; <a href=\"https:\/\/possiblelossofprecision.net\/?p=805\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[31],"class_list":["post-805","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-google"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=805"}],"version-history":[{"count":8,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/805\/revisions"}],"predecessor-version":[{"id":2683,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/805\/revisions\/2683"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}