I would like to present users to my website with an advertisement once per day. To accomplish this, I have tried to create a module that will set a cookie when they visit for the first time and show them the ad. Then, for every subsequent page, it checks for that cookie and shows them the regular content if they've seen the ad already.

However, using the code below doesn't seem to work very well. People are seeing the ads more than once per day.

You can see the code at http://www.inthehack.com/ad_module.txt though you'll need to do a view source on that page, as its showing as HTML.

A few questions:
1. Is there another, better way to do this, rather than to call a module and check for a cookie on every page? I couldn't think of any.
2. Is there a module that already does this? Front page is similar, but I don't think it can do this functionality. Correct me if I'm wrong.
3. Any ideas on why people are seeing the advertisement more than once? I've tried to disable the cache, but it doesn't seem to help.

Feel free to take and share the above code if it is of any use to you.

Thanks for your help,
Mike

Comments

xand’s picture

people are seeing the advertisement more than once most likely because cookies are blocked.

I suppose you could make it place a cookie, then try to read the cookie, and if that fails, just don't show the ad. At least the muliple ads problem won't persist, but you'll lose ad display to those people who block all cookies...