Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Ad Weighting Logic.

Quote Reply
Ad Weighting Logic.

I am working on an advertisement script, and there is something I need help on, and that is the best way to get ad weighting to work.

I know that I could do it by setting the weighting to 5 and that puts 5 entries in the table, but I don't want to do it that way. I want to set a number so that the higher the number, the higher the chance it has of being shown.

I just can't get the logic into my head how to do this. What would be the most effiecent way to do this? Any help would be greatly appreciated!

Michael Bray
Quote Reply
Re: Ad Weighting Logic. In reply to
Interesting question. This might be better to be asked in the PERL/CGI forum, since it's really a program logic question.

I know this sounds like a stock answer, but it does depend on how you have the logic set up with.

I gather you are putting the ads into a table, and you want to set a priority. For a small number of ads, one way would be to create a "run" table and enter the ID of the ad the # of times of it's priority. Then, you pick a random number 1 to #max_entries_in_run_table and use that serve up the banner. Actually, this sort of look-up table idea is the basis of a preferred way of starting to serve up ads, since you separate the display characteristics from the ad characteristics.

I wrote one or two very, very long messages about this some time ago.

You want to have a table for the 'advertiser' information, you need a table for the "campaigns" and a table for the "ads". You also need to set up "zones" (spaces on your site) that an ad fits into.

You need to take the information and "compile" it into a run-table, in order to handle a request for an ad in a timely (real-time) fashion.

The less complex your advertising system (or site) is, the less need there is for a compiled run-table.

The need for the run-table is such:

The run table contains only "information about" an ad or banner and it's zone-availability. Your program says "I need an ad that fits x,y,z criteria" That is run against the run-table, and an some values pop up. These values are passed to the template/browser/script whatever, that then has enough information to make the call to display the right ad.

This also leaves a second level of abstraction or randomization available, if the data passed back to the calling function is a randomized data set, or script, then that script can be the one that actually pulls the banner from the specified pool (zone-pool) once that information has been calculated.

Does this make sense?

banner advertising can get to extremely complex and incredibly maddening degrees of functionality. That is why some programs are "Free" or $30, and others are $25,000. It's not all "performance" but how well the program can manage hundreds, or thousands of campaigns, zones and advertisers.

FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Ad Weighting Logic. In reply to
Yeah - I was going to ask there but I think that the people in this forum know SQL alot better then most of the people that are in the PERL/CGI forum.

Your right about these things getting complex. Even thinking about how its going to work is giving me a headache :).

The script I am going to make will basically be WebAdverts in PHP/MySQL (written more effiecently), and will have billing built in.

I have started on it a few times and always get stuck in logic problems and just keep giving up :( My newsletter script is much more simple :)

Michael Bray
Quote Reply
Re: Ad Weighting Logic. In reply to

lets say you have 4 ads to display.
You want them to display with following


generate a random number between 1 an 100

if the number is

1-25 display ad1
26- 75 display ad2
76- 85 display ad3
86-100 display ad4

to get statistically correct answers you need to
implement the "Gaussche Normalverteilung" ( I don't
know the english word ) which is a quite complex

If you need someone to code it in pearl, contact me.

regards, alexander

Quote Reply
Re: Ad Weighting Logic. In reply to
LOL - My program it in Perl when there is PHP :). I understand what you are saying though about the weightings and I guess that would be a fairly effiecent way to handle it.

Having to add them up, work out each as a percentage and then choose the random number etc each time wouldn't be the best thing though would it?

That is the best solution I have heard or so far though.

Michael Bray
Quote Reply
Re: Ad Weighting Logic. In reply to
php is too simple..

umm i think you should do something like this.. weight field.. just like 1 being the lowest and no max.. and then you get the sum of the field..

select sum(weight) from ad

get random number using sum of weight.. (floating point number)

$random = rand $weight;

divide by weight.. to get a percentage (floating point number)..

$percent = $random / $weight;

get total ads..

select count(*) from ads

multiply by percentage

$offset = int($total * $percent);

get the ad..

select * from ad limit $offset, 1

heigher weights get more chances.. it makes sense..

i still like perl better than php.. php is just.. not good enough..

btw.. i made that ad weight thing up as i went.. [:-)] i just wanted to say i don't like php.. and i guess i ended up with a good way of doing your weight thing

Jerry Su