Adding Google Adsense to your Office Live Small Business website

Google Adsense is a good income generator for many websites but how do you add it to an OLSB website? There are a number of techniques out there, but there is only one that does not violate Google’s T&C for the Adsense program. You will need to insert a custom module into your web page. In this example, I will use a Custom Footer Module. Replace the code in the XSLT textbox with the following:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="/Footer">
<script type="text/javascript"><![CDATA[<!--
google_ad_client = "pub-0000000000000000";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_ui_features = "rc:0";
//-->]]></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</xsl:template>
</xsl:stylesheet>


As you can see from the above, we had to add in the CDATA tag to make sure the content inside will remain intact as it goes through XSLT transformation. When you view the web page in a browser and view its HTML source, you will see that the original Adsense code appears as if it was copied directly, despite the fact that we added the CDATA tag above.

Remember to replace the google_ad_client = "pub-0000000000000000"; line with your own publisher id!

39 Comments

William Pyle says: 13 November 2008 - 12:41 pm

I’m able to mess with the code in the header and footer, but is there anyway to put in my own html in the main body without giving me the error about defer was added because of scr and then my html changes to a junk html code. Can you help?

Tony Ross says: 7 March 2009 - 5:49 pm

I have tried the above solution and I get an error message from Office Live that states, “Problem with XSLT code. May contain an infinite loop, may be working on a very large data set, or may contain syntax problems. An error occurred while parsing EntityName.Line 1, position 46.

I have reviewed the code and do not see any syntax errors. Do you have any suggeestions?

admin says: 8 March 2009 - 9:26 pm

Hi Tony, I’ve checked your code you sent me. You have an extra

element in it (right after - just double check your own code with mine when you doubt). Just remove that and it’ll work. Also, dont’ forget to change your publisher ID to your own!
Donna Kirby says: 9 March 2009 - 11:22 am

Hello There!

I’m having a hard time getting my Adsense to work on my site - I’m positive it’s operator error :-) , but I don’t know what I’m doing wrong. I copy your text above, delete the existing XSLT code, paste the new text in (with my publisher ID changed - thanks for that heads-up!), and I keep getting an error that reads: “The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.” They may as well have posted this in Greek because I have no idea what any of that means. I just want to be able to run some Google ads on my site - what do you think it is that I’m doing wrong? Thanks so much for your help, direction and/or advice!

Andy Moran says: 9 March 2009 - 1:00 pm

Hi, I have the same problem as william when ‘defer’ is added to my html code because of ’scr’, which stops the code from working properly.

Is there any way I can stop ‘defer’ being added or anything else i can do to keep my code exactly the same please??

Christine Magtoto says: 17 March 2009 - 8:29 pm

This works! Thank you for the help!

DJ Thayer says: 18 March 2009 - 12:24 am

I tried this solution and I get no results. There is something blocking the code

admin says: 18 March 2009 - 1:25 am

@Donna: Glad that it’s now working great for you. Sometimes cut and paste from a web page may include additional characters, so it’s best to copy the code, paste it in a text editor such as Notepad, make sure the code is fine, and then copy the code again from the text editor and paste it into the XSLT box.

admin says: 18 March 2009 - 1:29 am

@Andy: You are putting the code in the HTML module instead of the Custom Footer. If you put the code in a Custom Footer, you will not encouter the issue with the ‘defer’ attribute.

admin says: 18 March 2009 - 1:31 am

@DJ Thayer: What is blocking the code? Just try copying the code exactly (without using your own pub-id or customization yet) to make sure it works first. Once you know that it works, change the code to match your own customization / pub-id for Adsense.

konadan says: 19 March 2009 - 1:12 am

did anyone check the adsence is working in different browser, IN my case I managed to add adsence. but when I open in IE it won’t come up…in chrome it displaying..That means the public using IE won’t see adsence. Y it happening.how to solve it.

larry says: 26 March 2009 - 4:34 pm

@admin i am having the same problem inserting adsense code. in your reply to andy you said that you put the code in the footer, not the html module.i tried that and adsense code just appears as script. can you help. explaining in none technical language. thanks in advance.

Darshan says: 28 March 2009 - 5:06 am

it worked thnx a million!!!!!!!

admin says: 30 March 2009 - 4:19 am

@larry, can you paste the code you used (just copy and paste from the XSLT textbox).

admin says: 30 March 2009 - 4:22 am

@konadan, the solution works for IE, Firefox, Chrome, etc. Nothing browser-specific was used in the code.

Ivy B says: 2 April 2009 - 5:23 am

it didn’t work for me either- just shows up in the footer as written HTML _It would be SO NICE if microsoft made it so you could actually edit your html modules. ZI mean why are we having this propblem -it’s supposed to be microsoft! I’m planning on taking my domain some where else!

Syntia says: 6 April 2009 - 10:10 am

How do I insert a custom module on my web page?

admin says: 9 April 2009 - 5:55 pm

@Ivy B. I believe you are adding the code directly to the Footer insetad of using Custom Footer, which is completely different. If you use Custom Footer, the script code will not appear on the webpage.

admin says: 9 April 2009 - 5:56 pm

@Synthia You will need to activate Advanced Design Features in Office Live (Page Manager->Site Actions->Activate Advanced Design Features). Once you have done that, go into Page Editor and you will see additional modules (including Custom Footer) in the Modules section.

Gandharv says: 13 April 2009 - 12:12 am

Hi I tried adding the above code with my pub id, it throws an error stating

There’s a problem with the XSLT code. It may contain an infinite loop, may be working on a very large data set, or may contain syntax problems. Please check the code and try again.

An error occurred while parsing EntityName. Line 1, position 61.”
Please help

admin says: 20 April 2009 - 6:32 pm

Gandharv: you sure you pasted everything in correctly?

LARRY says: 24 April 2009 - 10:49 am

HI hi there, soft prism/admin A BIG THANKS to you i have been trying to sort this problem for way to long. i had tried lots of solutions, and even emailed adsense and msol helplines, who where totaly useless. but by luck i found your link on the msol forum. problem solved simply and quickly in plain english. unlike most of the answers you find on the internet. once again THANKYOU, LARRY.

christina says: 26 April 2009 - 12:56 pm

ok im trying to put google adsense into my webite. its not working! how do i resolve this problem? i out it in the custom footer it comes up with the code. i also need to know how to add a column to my page? so i can put it in there.

christina says: 26 April 2009 - 12:57 pm

thank you because im going crazy trying to figure this out!

Marilyn says: 1 June 2009 - 12:00 am

Hi Larry -

I’ve tried this at least a hundred times, so I sure hope you can see where my mistake lies. Once, I got it, but something went wrong with my new site, and I lost it, plus I need to be able to add ads more than once, anyway. Here’s what I have:

<![CDATA[]]>

When I put that in, what comes up on my page is a little dotted blue box, that’s all. Oh do I hope you can help! Thanks so much!!

royster says: 2 June 2009 - 2:23 am

@christina: Just responded to you via email.

royster says: 2 June 2009 - 2:24 am

@Marilyn: Just responded to you via email. And yes, the empty blue rectangle showing up in Page Manager is normal. You will need to view your website to see the Google Ads show up.

trevor says: 15 June 2009 - 7:55 pm

I get the same problem trying to add an Add To Any bookmarking widget. Matter of fact, I get the same error when I just leave the pre-filled in code that automatically populates the Custom Footer window. Clearly there’s something wrong behind the scenes with Office Live on this issue, and it doesn’t have anything to do with the code we’re all trying to enter. Office Live is too buggy!

royster says: 29 June 2009 - 4:14 am

@trevor: That shouldn’t happen with the default Custom Footer module. Try deleting the module and adding it again.

Vinayak says: 1 July 2009 - 2:08 am

As suggest below I have added following code in XSLT box, but its showing blank on my website, is this because my wesite backroung coclor is black, or need to do the changes in code?

<![CDATA[]]>

Michael says: 16 July 2009 - 5:10 am

When I follow these instructions it works but the adds are Google Anzeigen? Please help.

royster says: 23 July 2009 - 4:05 am

@Vinayak: Emailed you already, but yes, it should be blank after you have added the code. You will only see the Adsense ads AFTER you actually view the website (not in Page Editor).

royster says: 23 July 2009 - 4:06 am

@Michael: Did you set the Google Adsense ads to another language?

Jokemi says: 24 July 2009 - 7:05 pm

Thanks!
It worked pronto!!!

Darcy Peal says: 13 August 2009 - 10:02 pm

There seems to be much confusion over this issue. I hope this clears it up.

1) You can insert the “Custom Footer Module” in ANY zone on your page. You DO NOT have to replace your existing Footer.

2) You MUST replace ALL the code between the CDATA tags with the code Google gives you.
<![CDATA[]]>

3) If you did 1 & 2 correctly the defer=”defer” statement WILL NOT be inserted.

4) My code is below and the AdSense it inserts may be seen at
http://mentalblockstosuccess.com/new_life
(Small Google AdSense at top-center of page)

(CODE REFORMATTED FOR CLARITY)

<![CDATA[]]>

5) As previously stated the module will only display as a dashed-line blue box. You must “View Site” and
perhaps refresh the page, to see your AdSense.

6) The default Module Size is “Fit To Content” . To change Right Click on the module, Left Click “Resize”, Click “Specify size (in pixels)” and enter your desired height & width.

7) Smile & have a great day everyone!

Darcy Peal says: 13 August 2009 - 10:19 pm

Sorry! Here is my URL and CODE again.

IE8 will probably not let use the link in my previous post so either use a different browser or go my HOME Page and click the “New Life” Tab to see how my AdSense turned out.

http://mentalblockstosuccess.com

<![CDATA[]]>

]]>

Andrew says: 18 September 2009 - 3:14 pm

Ok, what’s the error in the code? I know someone talked about that earlier, but I have no clue how this code should look! Lol. Here’s what I put into my Custom Footer (I learned how to use the Custom Footer option, quite cool!)

————————-

<![CDATA[]]>

—————————

What’s wrong with it? There’s some extra character, someone said, I believe. Man, I feel like I’m very close to getting advertisements working!! I await someone’s response. People here are quite helpful it seems. Also, I’m usually the type of person that gives out help, not takes it, so I know how much time it takes to answer things, and thank you for supporting Office Live!

Andrew

Andrew says: 18 September 2009 - 3:16 pm

^^^ Hmm, I guess the code can’t be pasted, and you can’t edit the data…

Just download my code in a Notepad document: http://thewingster.com/Documents/Adsense%20Code.txt

I hope that’ll give you the info necessary to assist me. Thank you again!!

Thank You says: 20 December 2009 - 3:22 am

You are a genius!

Leave a comment