A small ad-server proxy that speeds up local development ad server requests and permits local targeting overrides and insertions. It proxies interactions with our ad serving partner OpenX.
- Download or clone this repository
- Install the required gems via
bundle install
- Create your own
overrides.yml
and customize it. (To start, I would suggest copying or renamingoverrides.yml.example
) - Start the server
bundle exec rackup
. This starts on Sinatra's default port: 9292. (use-p <port number>
to start it on a different port)
This server responds to two end points:
example
<script src="http://localhost:9292/jstag&url=http%3A%2F%2Fox-d.example.com%2Fw%2F1.0%2Fjstag" type="text/javascript"></script>
If you are using OpenX's javascript library to get Multi ad unit integration, the initial request to http://d.example.com/w/1.0/jstag
should be routed through proxy, which will automatically route the request for ads through the proxy.
This will fetch OpenX's main javascript library. It updates the fetchAds
function and caches the result, now all future ad requests will be routed through the proxy.
The updated function behaves like this. (this is simplified to highlight the single change the proxy makes).
fetchAds = function() {
var url = 'http://localhost:9292/mock?url=' + encodeURIComponent(createAdRequestURL());
E.template(E.Templates.SCRIPT, {
src: url
});
E.write()
};
example
<script src="http://localhost:9292/mock&url=http://your_ad_server.domain.com/w/1.0/acj?o=1133877895&callback=OX_1373833895&ju=http%3A//this.is.fake.com%3A3000/&jr=&tid=16&pgid=13822&auid=561878%2C564363%2C463317%2C304996&c.browser_width=xlarge&res=1920x1200x24&plg=swf%2Csl%2Cqt%2Cshk%2Cpm&ch=UTF-8&tz=300&ws=1287x526&vmt=1&sd=1" type="text/javascript"></script>
If you are calling OpenX stand alone ads , you will need to route requests through the proxy. This means appending http://localhost:9292/mock&url=
to all requests for ads.
- The ad server has to have the correct targeting, and knowledge of all the ad units.
- There is also a 5-60 minute delay for any changes.
- Each request requires a round trip to get the ad data from the server.
To overcome these limitations here is a small proxy server that does the following:
- Cache OpenX responses
- Override ad units configured in a yaml file.
- Inject ad units configured in a yaml file.
- When enabled, Chorus will proxy the full ad server request to a small Sinatra app.
- The proxy app will respond with a redis-backed cached version if this request has been made before, if not it will request this information from the ad server and cache it.
- the proxy app then replaces or inserts any overridden ad units defined in
/overrides.yml
- It responds with a json string, formatted as through it was a response from the ad server.
- Faster responses from cached version of ad server code.
- Ability to override and insert our own local ad code for development without bothering adops
- and without waiting 15-60 minutes for targeting rules to propigate
A simple yaml file that contains the ability to enable and disable this proxy. note: Changing the ad_unit
configurations can be done without restarting the server.
enabled: true
ad_units: [
{
url_pattern: /verge/,
unit_id: 563927,
group_id: 0, # optional
width: 300, # optional
height: 250, # optional
html: '<div width="300px" height="250px"><img src="http://i.imgur.com/OsM2GBy.png"/></div>'
}
# ...
]
- Niv Shah – @nivshah
- Casey Kolderup – @ckolderup
- Clif Reeder – @clifff
- Skip Baney – @twelvelabs
- Brian Anderson – @banderson623
This is an active project and we encourage contributions. Please review our guidelines and code of conduct before contributing.
There are a few limited unit tests in /test/
. These can be run by executing bundle exec ruby ./test/ad_server_proxy_test.rb
.
Copyright (c) 2014, Vox Media, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
Neither the name of the {organization} nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.