Forum Moderators: martinibuster

Message Too Old, No Replies

Adsense channels and PHP Includes

Making the two play together

         

pulszar

4:23 am on Sep 29, 2006 (gmt 0)

10+ Year Member



I'm not sure if this belongs here or not, but since it's mainly about Adsense I figured AS users might know.

If you have a site that has, say, 8 or 9 subject pages (news, reviews, etc) that you use channels for adsense tracking, how can you incorporate the ads when using a SSI for a left bar, for example?

Another way to put it is, I have a left bar on a page with links, search, graphic, etc, plus an AS skyscraper.. but I want to have it linked to the "News" channel so I can track it's progress, how can I make that work with a SSI without splitting the left bar include in half? Is it possible? Or would I have to do something like:

<include leftbar top>
adsense code
<include leftbar bottom>

for each page I wanted a channel tracked ad?

Thanks in advance.

jatar_k

3:16 pm on Sep 29, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could do it inside the included file

maybe a switch on page name?

stormshield

4:33 pm on Sep 29, 2006 (gmt 0)

10+ Year Member



I'm not sure if I understood you. If you're working with PHP you could do something like this:
first list each channels you want to track, that is:

$news = "324234234";
$tutorials = "4555445";

and so on

then make some condition, let's say the name of the category is stored in $_GET['category']

if ($_GET['category'] == "news"){
$google_ad_channel = $news;
}

and so on

finally echo the adsense code and replace the number after "=" with the variable $google_ad_channel. Remember about escaping all quotation marks with "\". The whole code might look similiar to this:
<?php
$news = "324234234";
$tutorials = "4555445";

if ($_GET['category'] == "news"){
$google_ad_channel = $news;
}

echo "<script type=\"text/javascript\"><!--
google_ad_client = \"pub-somepub\";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = \"728x15_0ads_al_s\";
google_ad_channel =\"$google_ad_channel\";
google_color_border = \"FFFFFF\";
google_color_bg = \"FFFFFF\";
google_color_link = \"993300\";
google_color_text = \"000000\";
google_color_url = \"999999\";
//--></script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">

</script>";

?>

In this way you can track many channels.

Hope it helped
Storm

netmeg

5:04 pm on Sep 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yea, but you aren't supposed to modify the adsense code, are you? Would that break TOS?

jatar_k

5:15 pm on Sep 29, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it shouldn't, the delivered code would be as is

essentially you could generate the code for each page/channel and then use php to make the changes to account for the different channels

pulszar

6:01 pm on Sep 29, 2006 (gmt 0)

10+ Year Member



Stormshield: Thanks a million for your example.. I think I get what you are saying, and in fact I had a thought somewhat similar to this earlier this morning - I am still very new to php though so this might not work but is this a possibility?:

You know how you use php to change the title of each new page? $title is in the include and the actual title name of the page is in the page? Well could you do something like that for the adsense code?

What I'm thinking is, you put the same kind of php code you use for the title (in the include) in the position where the adsense code would go (in the left bar, in the include). Then in the .php file where your content goes, you would have code similar to that which names your title page.. something like:

$title = "Title name here"; (something like this)

BUT, instead of 'adsense-news', you would use an include there to call the specific adsense code with the channel info for that page. Maybe something like:

<?php
$adsense = include('ads/adnews.php'); (you get the idea)
?>

So it would work in the same way of naming the title on a per page basis, but call an include which would have your specific adsense code instead. This way you aren't editing the adsense code, and for the 8 or 9 pages that I'm dealing with, if I made any changes to the channels, size of the ad, etc, I could just replace the one file with the actual adsense code and control its placement with the single line in the include. I hope this all makes sense.

I assume most people with tons of pages that use adsense don't use channels to keep track of it - or maybe just a single channel for all news related pages or a single channel for all review related pages.

Either way thank you for the responses.

jatar_k

6:03 pm on Sep 29, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you want to get more in depth with php aspects then I can fire this over to the PHP Forum [webmasterworld.com] or you could post there.

sailorjwd

6:16 pm on Sep 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use a similar method as storm-

Except i'm using ASP.

I define the google channel as a variable on each page of the website (gvar="7654322345") and then use an include to bring in a snippet ASP that has the adsense code and uses the variable in the channel line.

This also allows me to switch to other ad methods quickly or even use a random number generator to show one ad vs another a certain percentage of time.

stormshield

6:33 pm on Sep 29, 2006 (gmt 0)

10+ Year Member



>So it would work in the same way of naming the title on a per page >basis, but call an include which would have your specific adsense code >instead. This way you aren't editing the adsense code, and for the 8 or >9 pages that I'm dealing with, if I made any changes to the channels, >size of the ad, etc, I could just replace the one file with the actual >adsense code and control its placement with the single line in the >include. I hope this all makes sense.

Well, that's certainly an option, however, I think you should fear changing the code in the way I did it in my last post. This certainly doesn't go under "modifying code" because the output of this PHP script is just a regular javascript code. Correct me if I'm wrong.

Pulszar, try to make it all work and let know if any further questions.

Good luck
Storm

webdudek

6:58 pm on Sep 29, 2006 (gmt 0)

10+ Year Member



I use the method suggested by stormshield for a few months to track the performance of different sources.
I change the channel dynamically according to the source of traffic, to check which source of traffic performs the best.
This is very easy to do, and there is no TOS violation - the code looks the same as the original.

pulszar

7:50 pm on Sep 29, 2006 (gmt 0)

10+ Year Member



I moved the thread to the PHP forum. I will try a few things out this weekend but I had one more question about your code Storm.

Here's the new thread: [webmasterworld.com ]

Thanks again for all the help, much appreciated.