Stay organized with collections
Save and categorize content based on your preferences.
Display a side rail ad
This example displays side rail ads using the Google Publisher Tag (GPT)
library. Learn more about side rail ads in the
Google Ad Manager help center.
Preview side rail ads
You can display a demo side rail ad on any page that shows ads with GPT by
adding #gamLeftSideRailDemo or #gamRightSideRailDemo to the URL. For
example, https://www.example.com/#gamLeftSideRailDemo.
This can be used to preview side rail ads on your site with no code changes
required. This is especially useful to quickly validate how side rails will
look and behave on different devices and in different operating environments.
Usage notes
To ensure an optimal user experience, side rail ads are only requested on
pages that properly support the format. Because of this,
defineOutOfPageSlot() might return null. Check for this case to
ensure you're not doing unnecessary work. Side rail ads are
supported when the following conditions are met:
GPT is running in the top window.
Viewport dimensions are at least 1200x650 pixels.
Only request side rail ads on pages and environments where you want a side
rail ad to appear. Side rail ads are eligible to serve to all devices.
Side rail ads generate their own ad container. You don't need a
<div> for side rail ads. Side rail ads
automatically create and insert their own container into the page when an ad
fills. These containers are positioned as close as possible to the main
page content.
Side rail ads are optimized to fit the space available. Side rail ads
require a minimum of 120x500 pixels of empty space to the left or right
of the main page content to display. Once displayed, if the page is resized
causing the empty space to fall below this minimum, the slot is temporarily
hidden until space becomes available again.
If using single-request architecture (SRA) on a page with multiple slots,
don't call display() until static ad slots divs are created. As
explained in Ad Best Practices, the first call to display()
requests every ad slot defined prior to that point. Although side rail ad
slots don't require a predefined <div>, static ad slots do. Calling
display() before these elements are present on the page can result in
lower quality signals, reducing monetization. Because of this, we recommend
delaying the initial call until after the static slots are defined.
Only refresh visible side rail ads. When an side rail ad slot
is collapsed or not visible, all calls to refresh() are ignored. If you're
using googletag.setConfig({ disableInitialLoad: true }) to manually
control ad loading and refresh, the first call
to refresh() will trigger an ad request regardless of the slot visibility.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# Display a side rail ad\n======================\n\nThis example displays side rail ads using the Google Publisher Tag (GPT)\nlibrary. Learn more about side rail ads in the\n[Google Ad Manager help center](//support.google.com/admanager/answer/10452255).\n\nPreview side rail ads\n---------------------\n\nYou can display a demo side rail ad on any page that shows ads with GPT by\nadding `#gamLeftSideRailDemo` or `#gamRightSideRailDemo` to the URL. For\nexample, `https://www.example.com/#gamLeftSideRailDemo`.\n\nThis can be used to preview side rail ads on your site with no code changes\nrequired. This is especially useful to quickly validate how side rails will\nlook and behave on different devices and in different operating environments.\n\nUsage notes\n-----------\n\n- **To ensure an optimal user experience, side rail ads are only requested on\n pages that properly support the format.** Because of this,\n `defineOutOfPageSlot()` might return null. Check for this case to\n ensure you're not doing unnecessary work. Side rail ads are\n supported when the following conditions are met:\n\n - GPT is running in the top window.\n - Viewport dimensions are at least `1200x650` pixels.\n- **Only request side rail ads on pages and environments where you want a side\n rail ad to appear.** Side rail ads are eligible to serve to all devices.\n\n- **Side rail ads generate their own ad container.** You don't need a\n `\u003cdiv\u003e` for side rail ads. Side rail ads\n automatically create and insert their own container into the page when an ad\n fills. These containers are positioned as close as possible to the main\n page content.\n\n- **Side rail ads are optimized to fit the space available.** Side rail ads\n require a minimum of `120x500` pixels of empty space to the left or right\n of the main page content to display. Once displayed, if the page is resized\n causing the empty space to fall below this minimum, the slot is temporarily\n hidden until space becomes available again.\n\n- **If using single-request architecture (SRA) on a page with multiple slots,\n don't call `display()` until static ad slots divs are created.** As\n explained in [Ad Best Practices](//developers.google.com/publisher-tag/guides/ad-best-practices#use_single_request_architecture_correctly), the first call to `display()`\n requests every ad slot defined prior to that point. Although side rail ad\n slots don't require a predefined `\u003cdiv\u003e`, static ad slots do. Calling\n `display()` before these elements are present on the page can result in\n lower quality signals, reducing monetization. Because of this, we recommend\n delaying the initial call until after the static slots are defined.\n\n- **Only refresh visible side rail ads.** When an side rail ad slot\n is collapsed or not visible, all calls to `refresh()` are ignored. If you're\n using `googletag.setConfig({ disableInitialLoad: true })` to manually\n [control ad loading and refresh](//developers.google.com/publisher-tag/guides/control-ad-loading), the first call\n to `refresh()` will trigger an ad request regardless of the slot visibility.\n\nSample implementation\n---------------------\n\n[View demo](https://googleads.github.io/google-publisher-tag-samples/display-side-rail-ad/js/demo.html) This sample makes use of library features that are not fully supported when running in an iframe. To view a demo of this sample in a new window, click the **View demo** button above. \n\n### JavaScript\n\nLoading...\n----------\n\nLoading...\n----------\n\n[Improve this sample](https://github.com/googleads/google-publisher-tag-samples/tree/main/dist/display-side-rail-ad/js) [Report an issue](https://github.com/googleads/google-publisher-tag-samples/issues/new?labels=documentation&template=sample-feedback.md&title=Sample+feedback%3A+display-side-rail-ad/js)\n\n### TypeScript\n\nLoading...\n----------\n\nLoading...\n----------\n\n[Improve this sample](https://github.com/googleads/google-publisher-tag-samples/tree/main/dist/display-side-rail-ad/ts) [Report an issue](https://github.com/googleads/google-publisher-tag-samples/issues/new?labels=documentation&template=sample-feedback.md&title=Sample+feedback%3A+display-side-rail-ad/ts)"]]