Google Publisher Tag (GPT) Ad Configuration Documentation
21 min
short description google publisher tag (gpt) is google's advertising solution that enables websites and mobile applications to display targeted advertisements this system integrates with google ad manager (formerly doubleclick for publishers) to serve ads dynamically based on configuration parameters configuration files overview the main configuration files for ads are ads json defines ad slot configurations views json defines where ads are displayed within views gpt ad configuration structure 1\ basic gpt ad configuration in ads json { "id" "unique ad identifier", "providerconfig" { "type" "gpt", "networkcode" "your network code", "adunitcode" "your ad unit path", "sizes" \[\[300, 250], \[320, 50]], "sizemapping" "mapping name", "targeting" \[ { "key" "category", "value" "news" } ], "refreshseconds" "30", "domain" "example com", "autoresize" true, "outofpageslot" false, "outofpageformat" "interstitial", "fixedid" true }, "condition" { "comparevalue" "$context platform", "value" "web" } } 2\ gpt configuration fields reference required fields field type description example type string must be "gpt" "gpt" networkcode string your google ad manager network code "12345678" adunitcode string ad unit path in ad manager "/site/section/position" sizes gptadsize\[] array of ad sizes or "fluid" \[\[300, 250], \[728, 90]] optional fields field type description default example sizemapping string reference to size mapping configuration undefined "desktop mobile mapping" targeting adtargeting\[] key value pairs for ad targeting \[] \[{"key" "category", "value" "news"}] refreshseconds string auto refresh interval in seconds undefined "30" domain string required for android/ios apps undefined "example com" autoresize boolean enable automatic resizing for inline ads undefined true outofpageslot boolean create out of page ad slot false true outofpageformat outofpageformat format for out of page ads undefined "interstitial" fixedid boolean use fixed container id with "div gpt " prefix false true 3\ ad sizes configuration standard ad sizes \[300, 250] medium rectangle \[728, 90] leaderboard \[320, 50] mobile banner \[300, 600] half page \[160, 600] wide skyscraper fluid ad size use "fluid" for responsive ads that adapt to container size "sizes" \["fluid"] size mapping for responsive ads with different sizes per viewport "sizes" \[\[300, 250], \[728, 90]], "sizemapping" "responsive mapping" 4\ targeting configuration "targeting" \[ { "key" "category", "value" "news", "multivalue" false }, { "key" "tags", "value" \["sports", "politics"], "multivalue" true } ] 5\ out of page ad formats available formats for outofpageformat div standard div based ad bottom anchor anchored to bottom of page interstitial full screen overlay rewarded rewarded ad format top anchor anchored to top of page 6\ size mapping configuration create responsive ad behavior with size mappings { "type" "sizemapping", "mappings" \[ { "viewportsize" \[1024, 768], "adsizes" \[\[728, 90], \[300, 250]] }, { "viewportsize" \[768, 0], "adsizes" \[\[320, 50]] }, { "viewportsize" \[0, 0], "adsizes" \[] } ] } integration with views (views json) 1\ direct ad placement { "adid" "front ad gpt", "type" "ad" } 2\ ad in list content "datasource" { "type" "issue", "ad" { "adid" "front list ad gpt", "interval" 3, "after" 1 } } ad placement parameters adid references the ad configuration id from ads json interval show ad every n items in a list after show first ad after n items examples from current configuration example 1 basic gpt ad { "id" "front ad gpt", "providerconfig" { "type" "gpt", "networkcode" "123456789", "adunitcode" "/site/front/banner", "sizes" \[\[728, 90], \[320, 50]], "targeting" \[ { "key" "section", "value" "front" } ] } } example 2 mobile specific ad with conditions { "id" "mobile ad gpt", "providerconfig" { "type" "gpt", "networkcode" "123456789", "adunitcode" "/site/mobile/banner", "sizes" \[\[320, 50]], "domain" "m example com" }, "condition" { "comparevalue" "$context platform", "value" "mobile" } } example 3 auto refreshing ad { "id" "refresh ad gpt", "providerconfig" { "type" "gpt", "networkcode" "123456789", "adunitcode" "/site/refresh/banner", "sizes" \[\[300, 250]], "refreshseconds" "30", "autoresize" true } } example 4 interstitial ad { "id" "interstitial ad gpt", "providerconfig" { "type" "gpt", "networkcode" "123456789", "adunitcode" "/site/interstitial", "sizes" \[\[300, 250]], "outofpageslot" true, "outofpageformat" "interstitial" } } current ad placements in project based on the views json analysis, these gpt ads are currently configured front ad gpt front page banner ad front list ad gpt ad within front page article list (every 3 items, after 1st item) news ad gpt news section banner ad news list ad gpt ad within news article list (every 3 items) sport ad gpt sports section banner ad sport list ad gpt ad within sports article list (every 3 items) e paper ad gpt e paper section banner ad search ad gpt search page banner ad best practices use appropriate ad sizes for your layout and target devices implement size mapping for responsive designs set targeting parameters to increase ad relevance and revenue use conditions to show different ads for different platforms or contexts consider auto refresh for high traffic areas, but balance with user experience test out of page formats carefully to avoid disrupting user experience use fixedid when you need consistent dom element ids for styling or tracking common issues and troubleshooting ad not displaying check network code and ad unit path wrong ad size verify sizes array matches your css container dimensions mobile ads not working ensure domain field is set for app integrations targeting not working verify targeting key value pairs match your ad manager setup refresh not working check refreshseconds is a string, not a number typescript interface reference refer to projects/storefront/src/app/config/ad config model ts 58 84 for the complete typescript interface definition of gptadconfig