Ad Code

From Adzerk Knowledge Base

Jump to: navigation, search

Contents

Generating Ad Code

  1. Click on the Inventory tab in the web interface, and then click on the site you want to generate ad code for.
  2. Click Ad Code.

    AdCode ad code link.jpeg

  3. From the Size drop-down list, select the size of the ad you want to create a placement for. As soon as you select a size, the Tag field is filled with div code.AdCode select ad size.jpeg

  4. Copy the code in the Tag field and paste it where you want the ad to display on your site.

    AdCode div tag.jpeg

  5. If you want the placement to be in a zone, choose a zone from the Zone drop-down list.
  6. Copy the JavaScript in the Script Tag box. Paste this in the header of your site's HTML.

    AdCode head script.jpeg

  7. If you need to add another placement to the page, use the "+ Add Another" button.AdCode add another.png This will create a new div and update the JavaScript tag.

Your placement is set up! Now, you or your web developer should insert the code on your site. If your network is serving ads that are eligible for this placement, they will serve on the page.

Note: Before you place the tags on a page, check that each div matches its corresponding ID in the Javascript. For example:

<div id="azk75686"></div>

should match

ados_add_placement(650, 16803, "azk75686", 4);

or the ad code will not serve ads.

Serving Ads via the API

To place an ad call without using JavaScript tags, you can make a RESTful HTTP call to our Native Ads API endpoint.

Ad Code Overview

Adzerk offers four ad code options: Synchronous, Asynchronous, Email, and 3rd Party Ad Server.

Ad Code Options

Asynchronous code is our standard code. It loads ads independently of the rest of the page, so it won't slow down page loads. It is a JavaScript tag, with an HTML div that loads the placement from the JavaScript. When a web page loads with asynchronous ad code, the code indicates to the browser to continue loading everything else on the page while it waits for the creative from Adzerk.

Synchronous code loads on a page like it normally does: line by line, waiting for element. It can potentially slow down page loads, especially if the synchronous code is serving third-party ads that pass impressions from one server to another.

Email code consists of a static link and static image tag. It can only serve images, and not Flash or JavaScript/HTML creatives. This means it cannot serve tags from other networks. Only use email code if other options aren't available.

3rd Party Ad Server code is useful if you are serving Adzerk ads through another server (such as DFP), or if you need to serve ads to a platform where HTML cannot be used. Note that 3rd Party Ad Server code cannot be used with companion ads or other distribution options.

Ad Code Components

All Standard ad tags contain a comment that explains what the code loads:

 /* load placement for account: NetworkName, site: SiteName, size: 160x600 - Wide Skyscraper*/

The ados_add_placement() function loads the actual placement:

ados_add_placement(1613, 15404, "azk57720", 6);

The first number is your network ID. The second is the site ID. The string is the name of the placement. Adzerk generates this string randomly. This placement name must match in both the script and the div. The last number is the adType ID.

Changing the Number of Placements

By default, you can create up to 10 placements in a single block of ad code. If you need to add more, you can change this at the Channel level by using the following steps.

Note: Changing the number of placements is limited to users of the Network Tools app. If you want to change the number of placements without the app, please contact the Adzerk support team.

  1. Navigate to Inventory, then click Channels, then click All Sites to edit that channel.

    Changing the number of placements 01.JPG

  2. Go to the Step 2: Ad Settings section. In the Number of Ad Slots field, enter the maximum number of placements you want available in a single block of ad code.

    Changing the number of placements 03.JPG

  3. Click Save this Channel to finish.

Modifying the Ad Code

Serving Multiple Ad Sizes in One Placement

You can modify the last number of the ados_add_placement() function to serve multiple ad sizes in a slot. For instance:

ados_add_placement(23, 6872, "azk66721", [5,4,6])

This looks for an ad to show in any of those sizes (300x250, 728x90, 160x600) and resizes the div accordingly.

To learn which numbers your ad sizes are, generate ad code for those sizes first. Then, copy the numbers into a single ados_add_placement() line when you add the ad tags to your page. Be sure to separate the numbers by commas, and contain them in brackets.

Refreshing the Ad Code

To reload your ads or refresh after the page has already loaded, add .setRefresh() to the ados_add_placement function. Inside the parentheses, put the number of seconds before the ad is to change to a new ad. In the example below, "15" is 15 seconds:

ados_add_placement(650, 16803, "azk70681", 6).setZone(3055).setRefresh(15);

You can also add the ados_refresh() function to the script to have greater control of how your ad refreshes:

ados_refresh('azk70681', 15, false)

15 is the number of seconds until the next refresh, and true/false indicates whether to refresh the ad again after the initial refresh.

Refreshing Companion Ads

To refresh companion ads, modify the following refresh code and add it below your ad code.

<script type="text/javascript">
setInterval(function(){
document.getElementById("azk1111").innerHTML = "";
document.getElementById("azk2222").innerHTML = "";
document.getElementById("azk3333").innerHTML = "";
ados.run.push(function() {
ados_add_placement(1234, 56789, "azk1111", 766);
ados_add_placement(1234, 56789, "azk2222", 6);
ados_add_placement(1234, 56789, "azk3333", 6);
ados_load();
});},5000);
</script>

The "ados_add_placement" lines should be copy and pasted from the original ad code. The "getElementById" identifications must match the div IDs for the ads being refreshed. The "5000" denotes the number of milliseconds between each ad refresh.

Including Keywords

To serve a flight that is targeted to certain keywords, add the keywords after the ad placement code with ados_setKeywords();

ados_add_placement(650, 16803, "azk70681", 6).setZone(3055);
 ados_setKeywords('dodge, truck, SUV');

Separate each keyword with a comma, and enclose in single brackets.

Adding ados_setKeywords(); to your ad tags will set keywords for the entire ad request (which includes all of the placements called in the ad tags). This means that if you set a keyword for one placement, all of the placements in the tags will also be set for that keyword. To target a specific placement with a keyword, use multiple sets of ad tags, or add ados_load(); after each placement you need to set with a keyword. To set no keyword at all, use ados_setKeywords(""); after the placement.

To add keywords to Email ad code, append the keywords to the end of the <img> tag, using ?keywords=:

<img border="0" src="http://engine.adzerk.net/s/14889/0/4/89011487?keywords=keyword1,keyword2,keyword3"; />

Renaming the Placement

You can rename the div generated in the ad code, but the new name must match in both the script section and the div ID:

ados_add_placement(650, 16803, "above_the_fold_160", 6).setZone(3055);
 <div id="above_the_fold_160"></div>

Serving Specific Campaigns, Flights, or Creatives

Below are instructions on how to manually serve specific campaigns, flights, or creatives, but consider using the Adzerk Advertiser Mode app instead. The app will streamline the process for you, making it much easier and faster to do.

To serve specific campaigns, flights, or creatives:

  1. Generate 3rd Party Ad Server code.</li>
  2. Find the ID of the campaign, flight, or creative you want to serve:</li>
    • To find the ID of a campaign, use the last number in the link to the campaign's page in the web interface. For example:
    http://domain.adzerk.com/network/1578/brand/5091/campaign/7883
    • To find the ID of a flight, use the last number in the link to the flight's page in the web interface. For example:
    http://domain.adzerk.com/network/1578/brand/5091/campaign/7883/option/17814
    • To find the ID of a creative, right-click the creative on its flight's page, and then copy the link. The last number is the ID. For example:
    http://domain.adzerk.com/network/1578/brand/5091/campaign/7883/option/17814/creatives/19618/map/29052
  3. Modify the ad code to set the ID you want to serve:
    • For a campaign, include .setCampaignId()
    ados_add_placement(650, 16803, "azk70681", 6).setZone(3055).setCampaignId(7883);
    • For a flight, include .setFlightId()
    ados_add_placement(650, 16803, "azk70681", 6).setZone(3055).setFlightId(17814);
    • For a creative, include .setFlightCreativeId()
     ados_add_placement(650, 16803, "azk70681", 6).setZone(3055).setFlightCreativeId(29052);

Serving to Secure Pages

Adzerk's Standard ad code automatically serves to SSL/https or http web pages, so you don't need to modify anything.

If you're using Adzerk's Synchronous, Email, or 3rd Party Ad Server ad code, you will need to make one simple change. After generating ad code, you'll see the ad request is in "http://" format, like this:

<script type="text/javascript" src="http://static.adzerk.net/ados.js"></script>

or

<a href="http://engine.adzerk.net/s/redirect/15404/0/4/41392450">
Change this request to
https://secure.adzerk.net/ados.js
and your ads will serve correctly.

Tracking Clicks on 3rd Party Ad Servers

To pass in a click tracker for tracking clicks on a third-party server (like DFP), insert the server's click tracking macro in the .setRedirectURL() field in the 3rd Party Ad Server type ad code:

ados_addInlinePlacement(1613, 15404, 4).setRedirectUrl('-optional-click-macro-').loadInline();

Enclose the click tracking macro within the single quotation marks:

ados_addInlinePlacement(1613, 15404, 4).setRedirectUrl('%%CLICK_MACRO_HERE%%').loadInline();

Preventing Caching in the Email Ad Code

Browsers will cache images for Email ad code if the same URL is used for multiple email campaigns. To avoid this, you should make the URL unique each time you send a campaign.

Because the last part of the URL generated by our ad code page consists of a randomly generated string, just change that part, and the ads will serve properly without being cached.

For example, if the code you generate looks like this:

 <a href="http://engine.adzerk.net/s/redirect/14889/0/4/89011487">
<img border="0" src="http://engine.adzerk.net/s/14889/0/4/89011487" /></a>


then a great way to ensure the URL is unique is to use a time or date, like this:

<a href="http://engine.adzerk.net/s/redirect/14889/0/4/newsletter05212012">
<img border="0" src="http://engine.adzerk.net/s/14889/0/4/newsletter05212012" /></a>

Note that this string has to be the same in both URLs. Otherwise, the link will not work.

Adapting Adzerk’s Email Ad Code for Gmail

If you serve email ads to recipients who use Gmail, be advised that Google has begun to proxy calls to images. This means that Google uses their own IP address in place of the unique IP address of the recipient. Since Adzerk can’t record an email ad impression without registering a user’s IP address, this breaks email ads in Gmail.

An alternate way to identify unique users is to pass in a custom value unique to each recipient. That modified ad code looks like this:

<a href="http://engine.adzerk.net/s/redirect/53763/0/4/56880432?key=1234">
<img border="0" src="http://engine.adzerk.net/s/53763/0/4/56880432?key=1234" /></a>

The value of Key must be unique for each user and email sent. Key must also match in both the anchor and image tags.

Your email client should have a way of automating a unique code that you can append to the URLs as Key. For example, in MailChimp you can use merge tags to generate a string that includes the user’s email with the Unix timestamp in microseconds: *|EMAIL|**|DATE:y/m/d/u|*

Passing Querystrings In Email Ad Code

You can also append a single querystring to Adzerk's email ad tags, which will pass that value to the ad's landing page on a click. For example,

<a href="http://engine.adzerk.net/s/redirect/53763/0/4/56880432?UserId=5678">
<img border="0" src="http://engine.adzerk.net/s/53763/0/4/56880432?UserId=5678" /></a>

When the add is clicked, the querystring is passed intact:

http://www.adzerk.com/?UserId=5678

Using Dynamic Site Selection

Dynamic site selection is an ad code modification that automatically sets the SiteId for the ad code based on the domain where the tags are hosted. This feature can be used two ways:

  • Dynamic site tags prevent tags from serving on unauthorized domains. If dynamic site tags are served on a page whose domain isn't a Site in the originating network, the ad call will not complete, and no ads will be served.
  • Dynamic site tags let a publisher or network with many separate Sites use the same tags across all their sites with no modifications to the ad code. Standard ad tags require a unique SiteId for every site in a network, or impression and click data will not be tracked for individual sites. Dynamic site tags will track clicks and impressions for multiple sites, while using the same ad tags for each.



To use dynamic site selection:

  1. Make sure that every domain you intend to use the tags for has been created as a Site in your network. Note that subdomains will be counted as a separate site.
  2. Generate ad tags for the intended Ad Size and Zone on the Ad Code page.
  3. To prevent the tags from serving to unknown domains, modify the SiteId (the middle number in the ados_add_placement(); function) as 0, or, modify the ados_addInlinePlacement(); function in the 3rd Party Ad Server tags.
  4. To allow the tags to fallback to a default site if the domain is unknown, modify the placement function with the siteId of the fallback site. Any clicks and impressions from the unknown domain will be recorded as coming from the default site.
  5. Append the method enableDynamicSiteSelection() to the end of the function.



Once modified, your function will look like this:

ados_add_placement(1613, 0, "azk96446", 1).enableDynamicSiteSelection();

Or:

ados_addInlinePlacement(1613, 0, 1).enableDynamicSiteSelection().loadInline();

Your tags are now ready to be used on a page.