3 Replies - 578 Views - Last Post: 22 June 2013 - 10:18 PM

#1 travesty  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 67
  • Joined: 04-June 13

Creating an ad system like AdSense

Posted 22 June 2013 - 08:14 PM

So I want to create my own ad system like Google AdSense where the user hosting the ads would select the options for the ad on his/her site and then have it generate the code for them to paste it. The part I really don't know how to do is the part where its cross site. How do I get the ads to show up on other peoples sites? And how do I get the ads variables to work with the show_ad.js hosted on my site?
<script type="text/javascript">
 var ad_publisher = "5122";
 var ad_campaign = "11129";
 var ad_type = "vertical";
</script> 
<script type="text/javascript" src="url.com/show_ad.js">
</script>


I'm sorry if this is a bad or really simple question (very new to javascript), I just didn't know what to Google for this.

Is This A Good Question/Topic? 0
  • +

Replies To: Creating an ad system like AdSense

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3635
  • View blog
  • Posts: 5,756
  • Joined: 08-June 10

Re: Creating an ad system like AdSense

Posted 22 June 2013 - 09:20 PM

Hey.

First, you really don't want to be doing variable declarations in the global scope. That's just asking for trouble, especially on a site you are not in control of yourself.

There are any number of ways to do this, but I would suggest a simple iframe for dropping foreign content into a site. It gives you a fresh canvas, separate from the hosting site, which reduces the risk of your content messing with theirs, or theirs messing with yours. It's also a lot safer for the host, because cross-domain iframes are isolated from the main site.

As for passing the variables, I'd suggest just putting them in the query string.
<iframe src="http://adservice.example.com/?p=5122&c=11129&t=v" height="100px" width="25px" frameborder="0"></iframe>



Unless you have a specific reason for needing Javascript code executed on the hosing site, this should do fine. If you do need the Javascript, you can still use the query string to pass the variables. Any server-side language (PHP, ASP.NET, Java, Python, etc...) can easily pick those up and inject them into the Javascript code before it is served. No need to require Javascript variables to be defined on the host site.
Was This Post Helpful? 0
  • +
  • -

#3 travesty  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 67
  • Joined: 04-June 13

Re: Creating an ad system like AdSense

Posted 22 June 2013 - 09:38 PM

View PostAtli, on 22 June 2013 - 09:20 PM, said:

Hey.

First, you really don't want to be doing variable declarations in the global scope. That's just asking for trouble, especially on a site you are not in control of yourself.

There are any number of ways to do this, but I would suggest a simple iframe for dropping foreign content into a site. It gives you a fresh canvas, separate from the hosting site, which reduces the risk of your content messing with theirs, or theirs messing with yours. It's also a lot safer for the host, because cross-domain iframes are isolated from the main site.

As for passing the variables, I'd suggest just putting them in the query string.
<iframe src="http://adservice.example.com/?p=5122&c=11129&t=v" height="100px" width="25px" frameborder="0"></iframe>



Unless you have a specific reason for needing Javascript code executed on the hosing site, this should do fine. If you do need the Javascript, you can still use the query string to pass the variables. Any server-side language (PHP, ASP.NET, Java, Python, etc...) can easily pick those up and inject them into the Javascript code before it is served. No need to require Javascript variables to be defined on the host site.

Thanks! I'll keep this in mind when working on it. So if I were using PHP I would just use this to get the variables?
$publisher = $_GET['p'];
$campaign = $_GET['c'];


Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3635
  • View blog
  • Posts: 5,756
  • Joined: 08-June 10

Re: Creating an ad system like AdSense

Posted 22 June 2013 - 10:18 PM

Yea basically like that, although you are missing the validation/sanitation you should always do when handling user input.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1