[{"data":1,"prerenderedAt":315},["ShallowReactive",2],{"\u002Farticles\u002Frolling-my-own-ad-platform":3},{"id":4,"title":5,"body":6,"createdAt":305,"description":306,"extension":307,"meta":308,"navigation":309,"path":310,"rawbody":311,"seo":312,"stem":313,"__hash__":314},"articles\u002Farticles\u002Frolling-my-own-ad-platform.md","Rolling My Own Ad Platform",{"type":7,"value":8,"toc":303},"minimark",[9,27,30,38,91,102,111,155,162,285,293,296,299],[10,11,12,13,20,21,26],"p",{},"Over the last few months, I’ve been working on a complete overhaul of our different websites in ",[14,15,19],"a",{"href":16,"rel":17},"http:\u002F\u002Flouisville.edu\u002Fdelphi",[18],"nofollow","my division"," at ",[14,22,25],{"href":23,"rel":24},"http:\u002F\u002Flouisville.edu\u002F",[18],"UofL",". Part of the design I landed on in the fall, incorporated an internal ad spot, where we could either advertise programs and offerings, or cross-sell them. I knew that I wanted to make this platform robust, but easy to use since people managing ads aren’t web developers. I landed on a solution that uses PHP\u002FMySQL on an different server and JavaScript to serve ad.",[10,28,29],{},"Here’s how I’ve got it setup:",[10,31,32,33,37],{},"Using jQuery, on ",[34,35,36],"code",{},"document.ready()",", I append my script from the remove server and pass the current URL:",[39,40,45],"pre",{"className":41,"code":42,"language":43,"meta":44,"style":44},"language-js shiki shiki-themes github-light github-dark","$('body').append('\u003Cscript type=\"text\u002Fjavascript\" src=\"http:\u002F\u002Fremoteserver.com\u002Fad.php?js&u=' + location.href + '\">\u003C\u002Fscript>');\n","js","",[34,46,47],{"__ignoreMap":44},[48,49,52,56,60,64,67,70,72,75,79,82,85,88],"span",{"class":50,"line":51},"line",1,[48,53,55],{"class":54},"sScJk","$",[48,57,59],{"class":58},"sVt8B","(",[48,61,63],{"class":62},"sZZnC","'body'",[48,65,66],{"class":58},").",[48,68,69],{"class":54},"append",[48,71,59],{"class":58},[48,73,74],{"class":62},"'\u003Cscript type=\"text\u002Fjavascript\" src=\"http:\u002F\u002Fremoteserver.com\u002Fad.php?js&u='",[48,76,78],{"class":77},"szBVR"," +",[48,80,81],{"class":58}," location.href ",[48,83,84],{"class":77},"+",[48,86,87],{"class":62}," '\">\u003C\u002Fscript>'",[48,89,90],{"class":58},");\n",[10,92,93,94,97,98,101],{},"I could add this script to the ",[34,95,96],{},"\u003Chead>"," or just before ",[34,99,100],{},"\u003C\u002Fbody>"," but due to the way the university’s system is setup, this is the best way. Since I’m using PHP\u002FMySQL to manage the indiviual ads, you’ll notice that the script is actually a PHP file. So what does this script do?",[10,103,104,105,110],{},"After reading this ",[14,106,109],{"href":107,"rel":108},"http:\u002F\u002F24ways.org\u002F2011\u002Fdefending-the-perimeter-against-web-widgets",[18],"article on 24 ways"," about not hurting a page when an external script was not available, I decided to set my script up the same way. So my script gathers ad based on the URL and some other details and runs a simple function that writes out HTML:",[39,112,114],{"className":41,"code":113,"language":43,"meta":44,"style":44},"\u002F\u002F ...database lookup and logic...\npublishAd('\u003Cdiv class=\"ad\">' + title + media + body + '\u003C\u002Fdiv>');\n",[34,115,116,122],{"__ignoreMap":44},[48,117,118],{"class":50,"line":51},[48,119,121],{"class":120},"sJ8bj","\u002F\u002F ...database lookup and logic...\n",[48,123,125,128,130,133,135,138,140,143,145,148,150,153],{"class":50,"line":124},2,[48,126,127],{"class":54},"publishAd",[48,129,59],{"class":58},[48,131,132],{"class":62},"'\u003Cdiv class=\"ad\">'",[48,134,78],{"class":77},[48,136,137],{"class":58}," title ",[48,139,84],{"class":77},[48,141,142],{"class":58}," media ",[48,144,84],{"class":77},[48,146,147],{"class":58}," body ",[48,149,84],{"class":77},[48,151,152],{"class":62}," '\u003C\u002Fdiv>'",[48,154,90],{"class":58},[10,156,157,158,161],{},"I know you’re asking yourself how is he running a function that doesn’t exist. Typically, this is when you see an ",[34,159,160],{},"undefined"," error in your console. It just so happens that I have the publishAd function defined in the same file as the append above. Here it is:",[39,163,165],{"className":41,"code":164,"language":43,"meta":44,"style":44},"function publishAd(content){\n    if(content.length > 0){\n        $('#ad-block').html(content).show();\n        $('#ad-block').fitVids();\n        $('#ad-block a').attr('target','_blank');\n    }\n}\n",[34,166,167,184,204,229,245,273,279],{"__ignoreMap":44},[48,168,169,172,175,177,181],{"class":50,"line":51},[48,170,171],{"class":77},"function",[48,173,174],{"class":54}," publishAd",[48,176,59],{"class":58},[48,178,180],{"class":179},"s4XuR","content",[48,182,183],{"class":58},"){\n",[48,185,186,189,192,196,199,202],{"class":50,"line":124},[48,187,188],{"class":77},"    if",[48,190,191],{"class":58},"(content.",[48,193,195],{"class":194},"sj4cs","length",[48,197,198],{"class":77}," >",[48,200,201],{"class":194}," 0",[48,203,183],{"class":58},[48,205,207,210,212,215,217,220,223,226],{"class":50,"line":206},3,[48,208,209],{"class":54},"        $",[48,211,59],{"class":58},[48,213,214],{"class":62},"'#ad-block'",[48,216,66],{"class":58},[48,218,219],{"class":54},"html",[48,221,222],{"class":58},"(content).",[48,224,225],{"class":54},"show",[48,227,228],{"class":58},"();\n",[48,230,232,234,236,238,240,243],{"class":50,"line":231},4,[48,233,209],{"class":54},[48,235,59],{"class":58},[48,237,214],{"class":62},[48,239,66],{"class":58},[48,241,242],{"class":54},"fitVids",[48,244,228],{"class":58},[48,246,248,250,252,255,257,260,262,265,268,271],{"class":50,"line":247},5,[48,249,209],{"class":54},[48,251,59],{"class":58},[48,253,254],{"class":62},"'#ad-block a'",[48,256,66],{"class":58},[48,258,259],{"class":54},"attr",[48,261,59],{"class":58},[48,263,264],{"class":62},"'target'",[48,266,267],{"class":58},",",[48,269,270],{"class":62},"'_blank'",[48,272,90],{"class":58},[48,274,276],{"class":50,"line":275},6,[48,277,278],{"class":58},"    }\n",[48,280,282],{"class":50,"line":281},7,[48,283,284],{"class":58},"}\n",[10,286,287,288,292],{},"A couple of things going on here: passing the HTML from above and only continuing if something exists; inserting the HTML into a predefined div on the webpage; binding the helpful ",[14,289,242],{"href":290,"rel":291},"http:\u002F\u002Ffitvidsjs.com\u002F",[18]," plugin to make videos responsive; and adding a target attribute to have all links in the ad open a new window.",[10,294,295],{},"What I won’t go into detail here is the administration side of this platform. I’ve built a simple webform for my colleagues to create text, image and video ads that they can set to start and end at specific times, only show on certain pages and other types of customization. That form saves their ad data to a database which the above ad.php reads from the print the ad.",[10,297,298],{},"This was a neat piece of our redesign that I had a lot of fun experimenting with.",[300,301,302],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":44,"searchDepth":124,"depth":124,"links":304},[],"2012\u002F02\u002F29","Over the last few months, I’ve been working on a complete overhaul of our different websites in my division at UofL. Part of the design I landed on in the fall, incorporated an internal ad spot, where we could either advertise programs and offerings, or cross-sell them. I knew that I wanted to make this platform robust, but easy to use since people managing ads aren’t web developers. I landed on a solution that uses PHP\u002FMySQL on an different server and JavaScript to serve ad.","md",{},true,"\u002Farticles\u002Frolling-my-own-ad-platform","---\ntitle: Rolling My Own Ad Platform\ncreatedAt: 2012\u002F02\u002F29\n---\nOver the last few months, I’ve been working on a complete overhaul of our different websites in [my division](http:\u002F\u002Flouisville.edu\u002Fdelphi) at [UofL](http:\u002F\u002Flouisville.edu\u002F). Part of the design I landed on in the fall, incorporated an internal ad spot, where we could either advertise programs and offerings, or cross-sell them. I knew that I wanted to make this platform robust, but easy to use since people managing ads aren’t web developers. I landed on a solution that uses PHP\u002FMySQL on an different server and JavaScript to serve ad.\n\nHere’s how I’ve got it setup:\n\nUsing jQuery, on `document.ready()`, I append my script from the remove server and pass the current URL:\n\n```js\n$('body').append('\u003Cscript type=\"text\u002Fjavascript\" src=\"http:\u002F\u002Fremoteserver.com\u002Fad.php?js&u=' + location.href + '\">\u003C\u002Fscript>');\n```\n\nI could add this script to the `\u003Chead>` or just before `\u003C\u002Fbody>` but due to the way the university’s system is setup, this is the best way. Since I’m using PHP\u002FMySQL to manage the indiviual ads, you’ll notice that the script is actually a PHP file. So what does this script do?\n\nAfter reading this [article on 24 ways](http:\u002F\u002F24ways.org\u002F2011\u002Fdefending-the-perimeter-against-web-widgets) about not hurting a page when an external script was not available, I decided to set my script up the same way. So my script gathers ad based on the URL and some other details and runs a simple function that writes out HTML:\n\n```js\n\u002F\u002F ...database lookup and logic...\npublishAd('\u003Cdiv class=\"ad\">' + title + media + body + '\u003C\u002Fdiv>');\n```\n\nI know you’re asking yourself how is he running a function that doesn’t exist. Typically, this is when you see an `undefined` error in your console. It just so happens that I have the publishAd function defined in the same file as the append above. Here it is:\n\n```js\nfunction publishAd(content){\n\tif(content.length > 0){\n\t\t$('#ad-block').html(content).show();\n\t\t$('#ad-block').fitVids();\n\t\t$('#ad-block a').attr('target','_blank');\n\t}\n}\n```\n\nA couple of things going on here: passing the HTML from above and only continuing if something exists; inserting the HTML into a predefined div on the webpage; binding the helpful [fitVids](http:\u002F\u002Ffitvidsjs.com\u002F) plugin to make videos responsive; and adding a target attribute to have all links in the ad open a new window.\n\nWhat I won’t go into detail here is the administration side of this platform. I’ve built a simple webform for my colleagues to create text, image and video ads that they can set to start and end at specific times, only show on certain pages and other types of customization. That form saves their ad data to a database which the above ad.php reads from the print the ad.\n\nThis was a neat piece of our redesign that I had a lot of fun experimenting with.\n",{"title":5,"description":306},"articles\u002Frolling-my-own-ad-platform","4NwtPZFawmkHPPY-mVuJ-nuv1aHzRgUnfGsd2GwYZvk",1794877726894]