From Adzerk Knowledge Base
Generating Ad Code
- Click on the Inventory tab in the web interface, and then click on the site you want to generate ad code for.
- Click Ad Code.
- 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
- Copy the code in the Tag field and paste it where you want the ad to display on your site.
- If you want the placement to be in a zone, choose a zone from the Zone drop-down list.
- If you need to add another placement to the page, use the "+ Add Another" button. This will create a new
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
ados_add_placement(650, 16803, "azk75686", 4);
or the ad code will not serve ads.
Serving Ads via the API
Ad Code Overview
Adzerk offers four ad code options: Synchronous, Asynchronous, Email, and 3rd Party Ad Server.
Ad Code Options
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.
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:
ados_add_placement() function loads the actual placement:
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.
- Navigate to Inventory, then click Channels, then click All Sites to edit that channel.
- 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.
- 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:
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:
You can also add the
ados_refresh() function to the script to have greater control of how your ad refreshes:
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.
document.getElementById("azk1111").innerHTML = "";
document.getElementById("azk2222").innerHTML = "";
document.getElementById("azk3333").innerHTML = "";
ados_add_placement(1234, 56789, "azk1111", 766);
ados_add_placement(1234, 56789, "azk2222", 6);
ados_add_placement(1234, 56789, "azk3333", 6);
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.
To serve a flight that is targeted to certain keywords, add the keywords after the ad placement code with
ados_setKeywords('dodge, truck, SUV');
Separate each keyword with a comma, and enclose in single brackets.
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
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
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:
- Generate 3rd Party Ad Server code.</li>
- 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:
- 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:
- 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:
- Modify the ad code to set the ID you want to serve:
- For a campaign, include
- ados_add_placement(650, 16803, "azk70681", 6).setZone(3055).setCampaignId(7883);
- For a flight, include
- ados_add_placement(650, 16803, "azk70681", 6).setZone(3055).setFlightId(17814);
- For a creative, include
- ados_add_placement(650, 16803, "azk70681", 6).setZone(3055).setFlightCreativeId(29052);
- For a campaign, include
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:
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:
Enclose the click tracking macro within the single quotation marks:
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:
<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:
<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:
<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,
<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:
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
SiteIdfor 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:
- 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.
- Generate ad tags for the intended Ad Size and Zone on the Ad Code page.
- 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.
- 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.
- 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();
ados_addInlinePlacement(1613, 0, 1).enableDynamicSiteSelection().loadInline();
Your tags are now ready to be used on a page.