I am trying to get Drupal configured fully for a switch from php-nuke to drupal, but a big thing that I'm having a problem with is Google Adsense. In php-nuke it was a sinch to put the javascript code in a block.

I'm working on creating a module for drupal that would let Google Adsense work, but because javascript filled blocks is dropped entirely from page created dynamically, this just isn't possible.

Anyone know of a way to get this to work properly? I've tried searching the forums but maybe I'm missing something.

Comments

media girl’s picture

JS is filtered out of most content by default. I understand that you also can use the PHP formatting option.

To turn off the header on the block, you can edit your style.css file. View source to find the ID tag for the Adsense block, and then set the H2 display to none. That should get you going.
--
mediagirl.org

keithmcd’s picture

Well, the Google Adsense thing is pure javascript. There's no way to make adsense work without javascript.

I tried everything I could think of, but there's no way to break out of javascript in a block. Using php to print the code, breaking out of javascript, using document.write, nothing works. If support for custom javascript will be added into 4.6, I'll just wait until that version, but until then Drupal will have to stay on a subdomain and not on my main site.

media girl’s picture

Mostly tracker routines. Follow the advice given here (explained much better below). You should have no problem.
--
mediagirl.org

Aran Deltac’s picture

Go to administer -> input formats

Then Add a new input format. I call mine "Raw".
Don't add any filters to your new input format. (its the html filter that is removing your javascript).
And make sure you are the only one allowed to use it. (its dangerous to let other people use an input format that doesn't filter)

Then, edit whatever thing you put your adsense code in and change to format to the one you just made.

keithmcd’s picture

I've tried all the suggestions given here, but I still can't get the Google Adsense to work. I created an input type with no settings attached, and tried using PHP input format.

The code I have in the "add block" textarea is the following:
<script src="/modules/google_adsense.js"></script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

Maybe I'm just missing something obvious, but i still can't get this to work and it's starting to get frustrating. You can see what's generated by going to http://bleak1.keithmcd.com and looking on the right just before the poll.

Thanks for all the help already given.

Aran Deltac’s picture

Looks like you ads are working just fine now. Did you fix it?

keithmcd’s picture

Yeah. I posted at the bottom of this page. It seems like the template I was using (goofy) was screwing up the code. I've got the google ads in a custom-made module. I'm gonna release it once I figure out cvs and how to get stuff up there.

nsk’s picture

If you take a look to my site you can see that Google Adsense appears very well.

I achieved that by placing AdSense in the Secondary Links of the Bluemarine theme.

What didn't work well was the Google Search code in Secondary Links. It seems that Drupal has some bugs regarding tables in Secondary Links. This must be fixed in future releases as it is very critical.

--
NSK, Admin of Drupal-based site http://www.wikinerds.org

tatonca’s picture

SImilar to NSK I also got google adsense to work using Secondary Links. I do also have it working in a block, simply by choosing the PHP filter option - really this is just an un filtered option with PHP functionality enabled. This has caused no trouble and works great (http://tatoncasworld.sytes.net)

One thing to be careful of - if you are trying to put google adsense on pages that cannot be spidered by gogglebot because they are not available to anonymous users you will end up with a blank block of the correct size. You may have to add the js variable that google uses for alternate ads, esp. for the skyscraper ad type, as no ads will be rendered for pages google hasn't spidered...

If you are using the smaller banner type, then you will just get PSA ads instead...

keithmcd’s picture

Well, it appears that the reason that all of your suggestions and why my custom module (I had written a custom module following the standards for an actual .module) wouldn't wouldn't work was the theme that I was using. The code generated by other themes somehow allows the module to work. Me thinks that it might be something with differences with phptemplate vs xtemplate.

Thanks for all your help.

iraszl’s picture

I'm trying to add the block with php or raw, but this is the error that i'm getting:

Terminated request because of suspicious input data.

---
http://creativebits.org

iraszl’s picture

Just to report back. I found the solution by switching on the bypass suspicious data in the admin permissions.
---
http://creativebits.org

iraszl’s picture

I have a dark and a light theme on my site. Users can choose their preference. However if I create a block with Adsense to match one of the themes it will not work with the other theme. How do I go about this?

1. Can I style the adsense ads with the theme CSS?
or
2. Can I by default assign a certain block to one theme, and another block to anothere theme?
or
3. Is there any other way?

Thank you!

---
http://creativebits.org

kbahey’s picture

Just created a new module. Check the announcement here http://drupal.org/node/23635

--
Consulting: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba