Campaign Manager 360 macros
Learn how to use each type of Campaign Manager 360 macro here.
Filter the table below to find what you need—for example, type in "tracking ads" to see every macro that works in tracking ads.
Click the help links to open detailed guidance on each macro.
|Macro||Name||Works in||Help link|
|%c||Click string macro||Creative code||Learn more|
|%e||Expand macro||Click-through URLs, Tracking ads, Redirect URLs, Creative code (all types), Impression event tags, Click event tags, OBA icon resource; Floodlight tags only support ||Learn more|
|%g||Geographic data macro||Click-through URLs, Tracking ads, Redirect URLs, Creative code (all types), Impression event tags, Click event tags, OBA icon resource||Learn more|
|%h||Creative server macro||Creative code (all types)||Learn more|
|%i||Impression macro||Interstitial placement tags||Learn more|
|%k||Keyword value macro||Click-through URLs, Tracking ads, Redirect URLs, Creative code (all types), Frame headers, Impression event tags, Click event tags, OBA icon resource||Learn more|
|%m||Match macro||Click-through URLs, Click trackers, Tracking ads, Redirect URLs, Creative code (all types), Impression event tags, Click event tags, OBA icon resource||Learn more|
|%n||Random number macro||Click-through URLs, Click trackers, Tracking ads, Redirect URLs, Creative code (all types), Floodlight tags, Impression event tags, Click event tags||Learn more|
|%p||Pattern match macro||Click-through URLs, Tracking ads, Redirect URLs, Creative code (all types), Frame headers, Floodlight tags, Impression event tags, Click event tags, OBA icon resource||Learn more|
|%s||Site keyname macro||Click-through URLs, Click trackers, Tracking ads, Redirect URLs, Creative code (all types), Floodlight tags, Impression event tags, Click event tags, OBA icon resource||Learn more|
|%u||Landing page URL macro||Creative code (all types), Impression event tags for display creatives with image assets||Learn more|
|Try your keywords on Google Web Search.|
Intro to macros
What are Campaign Manager 360 macros?
Campaign Manager 360 macros are short commands that the Campaign Manager 360 ad server expands into corresponding values—such as keywords, site keynames, or URLs. Some macros help log reporting information. Other macros determine which ad is served or where the ad redirects users after a click. Most macros are just a few characters long, which makes them easy to insert into your tags. You can insert Campaign Manager 360 macros into various contexts, including: a landing page URL, a click tracker tag, a redirect URL, the HTML of a creative, a frame header, or a Floodlight tag. The macro may expand when the ad is served or after other events, such as a Floodlight call. It may also expand dynamically (with user-specific information). It depends which macro you use and where you insert it.
Not every macro works in every context. If you insert a macro into an unsupported source, the Campaign Manager 360 ad server may not expand the macro properly. Use the table below to match macros with the right sources. For example, you can see from the table below that Campaign Manager 360 ad servers will expand the
%g macro if you insert it in your landing page URLs, but they won't expand this macro if you insert it in a click tracker tag.
Campaign Manager 360 macros are case-sensitive. Always type them in lowercase. For example,
%cis a valid macro, while
%Cis not a valid macro.
You may use separators between macros if you wish, but it isn't necessary. If you do want to use separators, use a comma (
,) or a pipe (
|). Avoid using other separators unless you're an experienced trafficker, as some can cause problems if used in the wrong context.
To edit macros in vendor tracking URLs, use event tags. Here's the basic process: First you create an event tag in Campaign Manager 360. Then you add your vendor tracking URL to the event tag. This can be a click-tracking URL, impression pixel, or survey URL. You can easily add or remove macros from your tracking URL in the event tag properties in Campaign Manager 360 . Once your event tag is ready, you can apply it to your ads. Your ads will use the tracking URL in your event tag when they serve. Campaign Manager 360 makes it easy to apply your event tag to many ads at once: for example, you can set your event tag to apply automatically to all the ads in your campaign. To get started, follow the steps in the event tag guide.
The only version of the expand macro that works in Floodlight tags is
%ers!. Learn more
%c — Click string macro
%c macro expands into the Campaign Manager 360 click string in your creative's landing page URL. A click string is the part of a landing page URL that points your browser to the Campaign Manager 360 ad servers.
%c_esc instead of
%c if you need to use an escaped version of the click string in a custom creative. Campaign Manager 360 click strings use ampersands (
&), which may cause problems if you work with third-party servers.
Note that the
%c macro will not expand to include click event tags for custom display creatives.
How click strings work: When a user clicks on a creative, the browser is pointed to the landing page URL. The click string redirects the browser to the Campaign Manager 360 ad servers before sending it to the advertiser's landing page. Campaign Manager 360 adds the click string to your click-through URL automatically at the time of each impression.
When to use
%c - If you manually add a landing page URL to the HTML of a custom creative, you may need to add the
%c macro to ensure that clicks redirect to the Campaign Manager 360 ad servers. You can also add
%u (the landing page macro) if you wish to expand both the click string and landing page URL:
%c%u expands into a complete landing page URL.
Steps to implement: Let's start with an example of a click string:
To add a click string to the landing page URL of a custom creative, position the
%c macro at the beginning of the landing page URL in the creative code, as in this click-through URL:
When an ad server serves a creative, the
%c macro expands into the click string. Here is an example of how the above landing page URL might look after the
%c macro at the beginning expands:
You can see the
%c has expanded into the click string at the beginning of the landing page URL, forming a complete creative URL.
To insert the whole creative URL at once, combine the
%c macro (click string) with the
%u macro (landing page URL):
<a href="%c%u">. The two macros expand into the complete creative URL.
For example, if you insert
<a href="%c%u"> into the HTML code, it might expand to:
%u expands into a landing page URL, any other macros in the landing page URL automatically expand as well, including the
%e — Expand macro
%e macro expands into the ID number for various properties of a creative. Insert an accessor after the macro to determine which ID number the macro expands into, and thus which creative property to track. See the list of accessors below.
You can use match tables to define these ID numbers and associate creative properties with them: the ID numbers are linked to the descriptions in Campaign Manager 360 (and in your own backend database). These ID numbers can help you track different properties of your creatives through the Campaign Manager 360 ad servers.
Floodlight tags only support one version of the expand macro:
%ers!. They do not support any other kind of
%e macro. Note that
%ers! works everywhere else that the expand macro is supported (see the table above).
If you're using tracking ads on mobile app inventory and are using a static landing page, the
%e macro will not expand properly.
List of accessors
Here are the accessors that determine which ID the expand macro (
%e expands into. Note that in these examples the
%e macro always comes before the accessor.
%eaid!- Expands to the ID of the ad served.
%eadv!- Expands to the advertiser ID associated with the ad served.
%ebuy!- Expands to the campaign ID associated with the ad served.
%ecid!- Expands to the ID of the creative served.
%eexcid!- Expands to the external ID of the Campaign Manager 360 campaign from which the ad served. This ID is pulled from the "External ID" field of your campaign properties. It is not generated by Campaign Manager 360. You may use external IDs outside Campaign Manager 360 to identify items in internal reports. Note that external IDs are not supported in click trackers. Learn more about external campaign IDs
%eexpid!- Expands to the external ID of the placement to which the ad served. This ID is pulled from the "External ID" field of your placement properties. It is not generated by Campaign Manager 360. You might use external IDs outside Campaign Manager 360 to identify items in internal reports. Note that external IDs are not supported in click trackers. Learn more about external placement IDs
%ekid!- Expands to an internal ID number used to identify a key-value pair that was targeted by the ad and that was matched when the ad was served.
%epid!- Expands to the ID of the placement to which the ad was served.
%erv!- Expands to the rendering version of the creative and changes whenever the rendering version is modified.
%eenv!- Expands to the environmental character. The environmental character is a one-letter code for the Campaign Manager 360 ad tag used to request the ad that is served. The letter that codes the environmental character is the same as the third letter in the Campaign Manager 360 ad tag (i.e., it is the letter that follows
ad). However, the environmental character for a standard ad tag is just a slash (
/), not a letter. See examples below.
%ers!- Expands to either
https, depending on the context. If the macro is on a secure site (site URL starts with
https), it will expand into https to match. If the macro is on a non-secure site (site URL starts with
http), it will expand into
httpto match. This protocol macro is useful if you want to make sure the protocol in your tag will always match the protocol of the site it appears on. However, note that
httpsURLs work fine on both secure and non-secure sites—so you don't have to use
httpin your tag just because the site URL starts with
%esid!- Expands to the site ID associated with the ad placement.
%erid!- Expands to the rendering ID. This macro is used internally in Campaign Manager 360 and corresponds directly to a creative ID. For debugging, the rendering ID is preferable to the creative ID provided by the
%ecid!macro, as the rendering ID is the lowest-level database object. Note that click trackers don't have rendering IDs; if this macro is used with a click tracker, the expanded value is
%eiid!- Expands to a unique click identifier. This macro is often used when tracking app install events with 3rd party click trackers.
%edclid!- Expands to an identifier in the landing page URL to enable enhanced attribution. This is good for selectively enabling enhanced attribution, or if URLs are not formatted correctly when the Floodlight enhanced attribution setting is enabled.
There is no limit to the number of
%e macros a landing page URL can contain. Here is an example of a landing page URL with three
%emacro can't be used for click trackers running on a Google Ad Manager site. On an Ad Manager site, properties such as the site name or advertiser ID expand with Ad Manager values, not Campaign Manager 360 values. Learn more.
%g — Geographic data macro
%g macro provides geographic information related to an ad request. It can be used to dynamically reflect the location of users in standard, custom, and Rich Media creatives. The
%g macro expands with a string of key-values for information such as country abbreviation, state abbreviation, city, postal code, Designated Market Area® Region, and Internet connection bandwidth. This information comes back to you through the Campaign Manager 360 ad servers.
%g might expand to the following for a user located in New York City:
%h — Creative server macro
%h macro expands into the host name of the server that serves a creative. This eliminates the need to hard-code the host name into your tag. The host name varies and the macro expands dynamically for each creative.
Add the macro to the beginning of the URL in your tag, such as in this image tag:
You should always use the
%h macro with creatives hosted by Campaign Manager 360
%i — Impression macro
%i macro expands into an impression string. The impression string allows the Campaign Manager 360 ad server to track impressions for an interstitial ad at impression time.
%i macro at the beginning of the URL in your tag, as in this example:
%i macro must be used in all interstitial ads, as it enables the Campaign Manager 360 ad server to track when an interstitial impression is actually served.
Warning: Only insert the
%i macro once into the code of an interstitial ad. Multiple statements of the macro will result in an inaccurate record of impressions.
%k — Keyword macro
%k macro expands into a substring found in the ad tags (specifically, in the request URL). You can use this macro to display user-entered keywords in creatives.
This macro is also useful to multiple keyword buys: it expands into any one of multiple keywords for the same creative, depending on which keyword the user enters. For example, consider how the
%k macro helps an advertiser with a keyword buy for both
car insurance and
car loans. When a user searches for
car insurance, the creative with that macro displays Click Here for Car Insurance; when a user searches for
car loans, the same creative displays Click Here for Car Loans.
Use a key-value pair to designate which substring the macro expands into. A key-value pair consists of a key (
start_key_string) and a corresponding value (
[start_key_string]- The key portion of a key-value pair. It must be included in the ad tags. Note that the
[end_character] - The character used to signify the end of a key-value. If an end character is not indicated, and the
start_key_string is the last key-value in a tag, the ad server copies the entire string.
Insert your macro and key-value pair in the following order: the macro, then the first value, then an exclamation point (
!), and finally the second value. The format looks as follows:
%k macro captures a substring designated by these parameters: it finds the keyword you designate and expands the macro into it. You can insert the key-value pair in an
ad Campaign Manager 360 tag or a
jump Campaign Manager 360 tag.
start_key_string is the last key-value in the tag, the
end_character is not necessary, and so in this case it isn't indicated in an
jump tag. Instead the ad server copies the entire string.
Another use of the
%k macro is to unescape escaped characters. When the macro passes a substring to the HTML of a creative, all of the escaped characters within the captured substring are automatically converted back to their original character sets. For example:
To display "
car insurance" in the creative, you must decode the escaped character "
+". So the advertiser embeds
%k in the creative's code. The ad server captures the substring
kw=car+insurance, decodes the
+ character, and displays it as car insurance in the creative.
Now the code looks like this:
<a href=http://www.car.com>Click Here for %kkw=!;</a>
A note on
%p macros: The two macros are similar in that they both capture a substring designated by the
start_key_string, but the two macros differ in how they pass the substring. Whereas the
%k macro passes the substring to the HTML of a creative, the
%p macro passes the substring to the URL. Unlike the
%p macro, the
%k macro only works within a creative's HTML code.
%m — Match code macro
%mmacro for users in California. Learn more
%m macro expands into a user's DoubleClick cookie value if browser settings make cookies available when the user clicks on the creative. One use of this macro is to generate a list of user IDs and then retarget users who have previously responded to the creative. The user ID is encrypted with the advertiser ID encryption key. Learn more about user ID encryption in your Campaign Manager 360 account.
You can insert the macro into the landing page URL, the redirect URL, the creative code, or a hard-coded click tracker such as
ad.doubleclick.net/clk. (The DoubleClick cookie value is a 64-bit integer with a maximum of 20 characters.)
Ad servers expand the
%m macro in the click string that follows a click event; they do not expand the macro within a creative.
- If a user disables cookies for their browser or has opted out of cookies, the ad server expands
- In creative code, the
%mmacro does not take effect for browsers that are behind a proxy. In this case the ad server also expands
By default, the
%m match macro is encrypted at the Campaign Manager 360 advertiser level, meaning it may be different from your Data Transfer encryption.
If your primary encryption for Data Transfer files is not designated as the Campaign Manager 360 advertiser level, then the
%m macro will not match. That means that the same user would be identified differently in each case.
If you want these values to match in your Campaign Manager 360 account, you can make a request to your Google Marketing Platform representative.
%n — Random number macro
%n macro expands into a random number. Random numbers keep browsers from caching a URL: when the ad serves, the ad servers dynamically generate a random number and append it to the URL in place of
%n. Because there is a new random number in the URL each time the ad serves, the browser can't load a cached version of the ad. When you defeat caching, you prevent third-party servers from undercounting impressions.
%n macro is often used on the publisher side when Campaign Manager 360 must redirect to a third party for a creative. Third parties typically have their own random number syntax, similar to Campaign Manager 360's
%n macro also enables third parties to track clicks. Because each user click expands a unique random number in place of the
%n macro, third parties can track each click separately. Traffickers should confirm with the third party that they support the additional character string that the macro expands into.
%p — Pattern match macro
%p macro expands into any value found between a start string and end character that you specify. Specifically, the macro expands into a substring found in the request URL of your ad tags: when the ad serves, the macro expands into whatever is found between your start string and end character.
Here is the basic format for your %p macro:
For example, say you want to capture whatever is between
?. In this case, you'd insert the
%p macro like this:
When your ad serves, Campaign Manager 360 searches for
apple in the ad tags and then captures everything between
apple and the end character, which in this case is a question mark (
?). Note that the brackets of the placeholders are not included (e.g.,
%p macro is used to expand into a keyword that helps track reporting information.
How to designate the substring: Use a key-value pair to define the beginning and end of the type of substring you wish the server to search for. A key-value pair consists of two key-values, a
start_key_string value and an
[start_key_string]: The key portion of a key-value pair. It must be included in the ad tags. Note that this is case-sensitive. Do not include the brackets. E.g., to use "apple" as a key, replace
[end_character]: The character used to signify the end of a key-value. If an end character is not indicated, and the start string is the last key-value in a tag, the ad server copies the entire string. You can enter each value as any string of ASCII values. The value should also be at least two characters in length. Do not include the brackets. E.g., to use "?" as the end character, replace
Some common uses for the
%p macro include:
Publishers passing values dynamically into landing page URLs.
%s — Site keyname macro
%s macro expands differently depending on whether you add it to ad tags or Floodlight tags.
Ad tags expand into the Campaign Manager 360 site keyname: When a user clicks on an ad served by Campaign Manager 360, this macro expands into the keyname of the site to which the ad was served. This keyname should match the keyname listed on the site's Properties tab in Campaign Manager 360 (Admin > Sites).
For example, consider this URL, which includes an
%smacro at the end:
If that URL is included in an ad served to a site with the keyname
N255.010101.sandwiches, then when the user clicks the ad, the macro expands to
If site info is not available in real time,
%smay expand to an empty string.
Floodlight tags expand into the Campaign Manager 360 site ID: When a Floodlight tag fires on a site, the %s macro expands into the ID of the site. This is the ID that Campaign Manager 360 uses to identify the site.
%smacro can't be used for click trackers running on a Google Ad Manager site. On an Ad Manager site, properties such as the site keyname or advertiser ID expand with Ad Manager values, not Campaign Manager 360 values. Learn more
%u — Landing page URL macro
%u macro expands into the landing page URL of a creative. For example,
<a href="%u"> might expand into the following landing page URL:
To insert the whole creative URL at once, combine the
%u macro with the
%c macro. The two macros expand into the entire URL:
%c (click string) +
%u (landing page URL) = a complete creative URL.
For example, if you insert
<a href="%c%u"> into the HTML code, it might expand to:
%uexpands into a landing page URL, any other macros in the landing page URL automatically expand as well.