Jump to content



Photo
- - - - -

How To Create My Own Javascript Sdk For Advertising

javascript sdk advertising client side

  • Please log in to reply
9 replies to this topic

#1 cleanlinesproductions

cleanlinesproductions

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 25 March 2012 - 3:13 PM

I need to make an advertising software development kit for users to integrate into their own website. I have a generous PHP & MySQL knowledge, but not so much for Javascript. I would like it to:

(a) Connect to the Database
(B) Select an Ad at random
© Not reveal anything about a PHP script
(d) Return as a frame

an example of what I need is like Google's AdSense program. If you look at an ad, it is in a frame. I need something like this.
  • 0

#2 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,960 posts
  • LocationColumbus, OH USA

Posted 25 March 2012 - 7:12 PM

If you don't mind me asking, why do you need JS at all for your solution? When the page loads, couldn't you simply use PHP to randomly select an ad from the DB, and then load that into an iframe (which is what Google's AdSense does)?

I'm not actually sure how Google's AdSense works behind the scenes though. If the ads are loaded into an iframe, then that would seem to suggest that the ads are seperate URLs that can be linked to, which may or may not be the situation in your case. Either way, iframes make sense in that they allow for the parallel loading of the ad content with the page content.

Anyway, if you need JS for some reason, you're going to want to look into Ajax. Also, if you're not confident in your JS skills, I'd start reading Larry's book first, and then come back here if/when you get stuck.
  • 1

#3 cleanlinesproductions

cleanlinesproductions

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 26 March 2012 - 12:39 PM

What I am looking for is also similar to the Facebook integration. It calls a javascript file and in the DIV tag it will have information on what to call specifically:

<div id="fb-like" data-width="450" data-height="100" data-href="myhome.com"></div>

This will tell the javascript to call the FB LIke item, style it to 450px wide and 100px high, and any action (liking the page) will insert info into the database for 1 like by a certain person, for a certain page.

I need to do this with a hosting company I work for. To have ads program, and an API for clocks, and other useful widgets. I need to have the ability to have users style it, and use it on their site to their custom style. If you need more info, just ask.
  • 0

#4 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,947 posts
  • LocationState College, PA (USA)

Posted 26 March 2012 - 3:38 PM

My recommendation would be to start by looking at the Google AdSense (public) code to see how they do it. I believe AdSense uses a bit of HTML and JavaScript to create an iframe in the page. The source of the iframe can be the PHP script that connects to the database. Should be relatively straightforward.
  • 0

#5 cleanlinesproductions

cleanlinesproductions

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 26 March 2012 - 4:06 PM

I don't really have a lot of JavaScript knowledge. And the AdSense code is REALLY complex. I just need it to create an IFRAME based on what is placed in the DIV tag.

<div id="ihost-widget" widget-type="clock" widget-width="125" widget-height="125" user-id="12491463"></div>

will create an IFRAME that access the URL:

api.myhostdomain.im/widget.php?type=clock&width=125&height=125&uid=12491463

I can create the widget PHP script. I just need the JavaScript.

And I cannot purchase Larry's book right now. I need to get this job done before I can get paid.
  • 0

#6 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,960 posts
  • LocationColumbus, OH USA

Posted 27 March 2012 - 12:47 AM

I'm not too familiar with dealing with undefined HTML element attributes like widget-type, etc. Basically, I don't think it's valid markup (well, maybe in XHTML). Anyway, the following sample script will give you what you want:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Google AdSense JS sample</title>

</head>

<body>

<div id="ihost-widget" widget-type="clock" widget-width="125" widget-height="125" user-id="12491463"></div>

<script>

var ihost_widgetDiv = document.getElementById('ihost-widget'),
widget_typeAtrb = ihost_widgetDiv.getAttribute('widget-type'),
widget_widthAtrb = ihost_widgetDiv.getAttribute('widget-width'),
widget_heightAtrb = ihost_widgetDiv.getAttribute('widget-height'),
user_idAtrb = ihost_widgetDiv.getAttribute('user-id');

document.body.innerHTML = 'widget-type: ' + widget_typeAtrb + '<br>';
document.body.innerHTML += 'widget-width: ' + widget_widthAtrb + '<br>';
document.body.innerHTML += 'widget-height: ' + widget_heightAtrb + '<br>';
document.body.innerHTML += 'user-id: ' + user_idAtrb;

</script>

</body>

</html>
  • 1

#7 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,960 posts
  • LocationColumbus, OH USA

Posted 27 March 2012 - 12:49 AM

I meant to put this in my other post, but anyway, after that, you will have to use Ajax to actually feed that info to a PHP script. Sorry, but I'm not going to just give you that code too. If you look at Larry's book or go online and search for how to use Ajax, you can probably figure it out though.
  • 2

#8 cleanlinesproductions

cleanlinesproductions

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 27 March 2012 - 3:26 PM

Thanks so very much. I got a code from elsewhere on how to create an IFRAME from javascript. So I put both codes together to make an IFRAME connected to the DIV attributes. This will help the company I work for, and our progress on creating the website,

Thanks again. Thanks to Larry for being an awesome author (I read his PHP & MySQL Visual Quick Pro Second Edition book)
  • 0

#9 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,960 posts
  • LocationColumbus, OH USA

Posted 28 March 2012 - 7:18 AM

Hope you get want you want.
  • 0

#10 cleanlinesproductions

cleanlinesproductions

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 28 March 2012 - 4:28 PM

I did. Thanks again
  • 0





Also tagged with one or more of these keywords: javascript, sdk, advertising, client side