2

I would like to hide my google adsense code from people trying to lookup all my sites.

One way that I have seen this online is:

Creating a java script file (AdSetup.js) with this:

    <!--
google_ad_client = "xxxxxxxxxxxxxxxxxxx";
google_ad_channel = "xxxxxxxxxxxxx";
google_alternate_ad_url = "http://www.digitalpoint.com/ads/ads.php?t=seo";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_color_border = "FF88FF";
google_color_bg = "FFCCFF";
google_color_link = "000066";
google_color_url = "222222";
google_color_text = "222222";
//-->

and adding this code to the web page:

<script type="text/javascript" src="AdSetup.js"></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

The above does sorta hide the code, but the file is still seen & accessible.

Could anyone please tell me how better hide/mask a javascript file location?

Im sure many other people would want to hide this code aswell and protect their online privacy.

Thank you

3 Answers3

2

I take your well known text, contents you know.

google_ad_client = "xxxxxxxxxxxxxxxxxxx";
google_ad_channel = "xxxxxxxxxxxxx";
google_alternate_ad_url = "http://www.digitalpoint.com/ads/ads.php?t=seo";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_color_border = "FF88FF";
google_color_bg = "FFCCFF";
google_color_link = "000066";
google_color_url = "222222";
google_color_text = "222222";

I add a bit of code(courtesy of how-do-i-include-a-javascript-file-in-another-javascript-file)

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);

Then before that I insert the url variable http://pagead2.googlesyndication.com/pagead/show_ads.js file

var url = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';

So in total this is:

google_ad_client = "xxxxxxxxxxxxxxxxxxx";
google_ad_channel = "xxxxxxxxxxxxx";
google_alternate_ad_url = "http://www.digitalpoint.com/ads/ads.php?t=seo";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_color_border = "FF88FF";
google_color_bg = "FFCCFF";
google_color_link = "000066";
google_color_url = "222222";
google_color_text = "222222";

var url = 'http://pagead2.googlesyndication.com/pagead/show_ads.js';

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
head.appendChild(script);

Then I base64encode this with https://www.base64encode.org/

en then I end up with:

Z29vZ2xlX2FkX2NsaWVudCA9ICJ4eHh4eHh4eHh4eHh4eHh4eHh4IjsNCiAgICBnb29nbGVfYWRfY2hhbm5lbCA9ICJ4eHh4eHh4eHh4eHh4IjsNCiAgICBnb29nbGVfYWx0ZXJuYXRlX2FkX3VybCA9ICJodHRwOi8vd3d3LmRpZ2l0YWxwb2ludC5jb20vYWRzL2Fkcy5waHA/dD1zZW8iOw0KICAgIGdvb2dsZV9hZF93aWR0aCA9IDQ2ODsNCiAgICBnb29nbGVfYWRfaGVpZ2h0ID0gNjA7DQogICAgZ29vZ2xlX2FkX2Zvcm1hdCA9ICI0Njh4NjBfYXMiOw0KICAgIGdvb2dsZV9jb2xvcl9ib3JkZXIgPSAiRkY4OEZGIjsNCiAgICBnb29nbGVfY29sb3JfYmcgPSAiRkZDQ0ZGIjsNCiAgICBnb29nbGVfY29sb3JfbGluayA9ICIwMDAwNjYiOw0KICAgIGdvb2dsZV9jb2xvcl91cmwgPSAiMjIyMjIyIjsNCiAgICBnb29nbGVfY29sb3JfdGV4dCA9ICIyMjIyMjIiOw0KDQogICAgdmFyIHVybCA9ICdodHRwOi8vcGFnZWFkMi5nb29nbGVzeW5kaWNhdGlvbi5jb20vcGFnZWFkL3Nob3dfYWRzLmpzJzsNCg0KICAgIHZhciBoZWFkID0gZG9jdW1lbnQuZ2V0RWxlbWVudHNCeVRhZ05hbWUoJ2hlYWQnKVswXTsNCiAgICB2YXIgc2NyaXB0ID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgnc2NyaXB0Jyk7DQogICAgc2NyaXB0LnR5cGUgPSAndGV4dC9qYXZhc2NyaXB0JzsNCiAgICBzY3JpcHQuc3JjID0gdXJsOw0KICAgIGhlYWQuYXBwZW5kQ2hpbGQoc2NyaXB0KTs=

This you put in your javascript file as a string variable and then eval it.

str = 'Z29vZ2xlX2FkX2NsaWVudCA9ICJ4eHh4eHh4eHh4eHh4eHh4eHh4IjsNCiAgICBnb29nbGVfYWRfY2hhbm5lbCA9ICJ4eHh4eHh4eHh4eHh4IjsNCiAgICBnb29nbGVfYWx0ZXJuYXRlX2FkX3VybCA9ICJodHRwOi8vd3d3LmRpZ2l0YWxwb2ludC5jb20vYWRzL2Fkcy5waHA/dD1zZW8iOw0KICAgIGdvb2dsZV9hZF93aWR0aCA9IDQ2ODsNCiAgICBnb29nbGVfYWRfaGVpZ2h0ID0gNjA7DQogICAgZ29vZ2xlX2FkX2Zvcm1hdCA9ICI0Njh4NjBfYXMiOw0KICAgIGdvb2dsZV9jb2xvcl9ib3JkZXIgPSAiRkY4OEZGIjsNCiAgICBnb29nbGVfY29sb3JfYmcgPSAiRkZDQ0ZGIjsNCiAgICBnb29nbGVfY29sb3JfbGluayA9ICIwMDAwNjYiOw0KICAgIGdvb2dsZV9jb2xvcl91cmwgPSAiMjIyMjIyIjsNCiAgICBnb29nbGVfY29sb3JfdGV4dCA9ICIyMjIyMjIiOw0KDQogICAgdmFyIHVybCA9ICdodHRwOi8vcGFnZWFkMi5nb29nbGVzeW5kaWNhdGlvbi5jb20vcGFnZWFkL3Nob3dfYWRzLmpzJzsNCg0KICAgIHZhciBoZWFkID0gZG9jdW1lbnQuZ2V0RWxlbWVudHNCeVRhZ05hbWUoJ2hlYWQnKVswXTsNCiAgICB2YXIgc2NyaXB0ID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgnc2NyaXB0Jyk7DQogICAgc2NyaXB0LnR5cGUgPSAndGV4dC9qYXZhc2NyaXB0JzsNCiAgICBzY3JpcHQuc3JjID0gdXJsOw0KICAgIGhlYWQuYXBwZW5kQ2hpbGQoc2NyaXB0KTs=';
eval(atob(str));

Please note, eval is evil, very evil. NEVER use eval on data that was submitted by users. Always know what you are evalling.

Community
  • 1
  • 1
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
-1

JavaScript is executed client-side by the user's browser. Fundamentally, that means it isn't possible to prevent the user from having access to that code.

Obfuscation to make it harder to read via minification/renaming variables/etc. is possible, but generally not with third-party libraries like Google's ads.

Your Google ad code is simply not private data. Not only is it impossible to prevent the user from seeing it, but there's really no reason to worry about it.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • I could have one website with my name on it, and another where I don't want my name public, this Google code allows people to match me as the owner of both websites. So I'm worried about it because of that. – Igor Jerosimić Aug 12 '21 at 21:45
  • @IgorJerosimić So use two different analytics accounts. Google makes it trivial to have more than one. (Also, the resulting IDs, even obfuscated, would still be visible in the network inspector. It wouldn't hide you there, either.) – ceejayoz Aug 13 '21 at 00:52
  • It's easy for Analytics, yes, but here we are discussing AdSense publisher ID. There does not seem to be a good solution unless Google decides to add separate code for each website like it's possible for Analytics... – Igor Jerosimić Aug 13 '21 at 12:12
-4

It's not possible (of course it is technically, but Google won't allow it you could obuscate it so reading it would be harder).

You are not permitted to change the AdSense code snippet and the pub attribute is needed to earn the money). You will have to show the pub attribute to everyone.

I also don't know why this would hurt your privacy because you can't search for the pub tag and find websites with that on it.

Luca Steeb
  • 1,795
  • 4
  • 23
  • 44