If you want to insert custom ads on your website using a single request, this can be achieved by creating custom code in a specific format and adding it using a widget in the page builder.
To implement this, you need to add the custom scripts in the Head and Body sections of the webpages via the Page Builder, following these steps:
- Log in to the Page Builder.
- Go to Settings > Manage> Insert Custom Code, and add the code in header of all pages, as mentioned below.
- Or insert the custom code or modified code in the required placement using the widget option.
Ad Dimensions:
Once the header and body scripts have been added, we need to modify the code that needs to be inserted and place it in the respective widget slots. Typically, we use the following ad sizes, but these may change based on your requirements:
- 728x90, 970x90, 320x50, 300x250
- 728x90, 970x90, 320x50, 300x250, 970x250
- 300x250, 300x600
- Right Side Rail Ad
- Left Side Rail Ad
-
Road Blocker Ads
Ad Code Placement:
- The right side rail ad, left side rail ad, and road blocker ads should be added to the top slot in the widget of the landing pages.
- The ad code with the sizes 728x90, 970x90, 320x50, 300x250 needs to be added just below the top slot in the landing page. This will be the top ad.
- The ad code with the sizes 728x90, 970x90, 320x50, 300x250, 970x250 should be added at the bottom of the page or the desired placement.
-
The 300x250 ad size should be inserted as per the required placement.
Modifying the GPT tags
- Create ad units as per the dimensions mentioned above.
- In the sample code, we need to replace the div ID "div-gpt-ad-1705653003339-0" and the "Ad unit ID" with the appropriate values for the specific ad unit. These will be different for each ad unit.
- If the same ads need to be rendered in multiple slots, instead of using the div ID "div-gpt-ad-1705653003339", you can replace it with a "unique-id".
Example: Replace "div-gpt-ad-1705653003339-0" with "unique-id".
Note: Below codes are just for example, this can be modified as per your requirement.
Example: Head code
<script async src='https://securepubads.g.doubleclick.net/tag/js/gpt.js'></script>
<script>var desktopAd=window.innerWidth>600;
var desktopAdBig=window.innerWidth>1550;
var mobileAd=window.innerWidth < 600;
window.googletag=window.googletag || {cmd: []};
</script>
<style>
.header-six-m__navbar-mobile__lQHAq .logo-wrapper img {
min-height: 100% !important;
}
.sticky-ad {
position: fixed;
top: 60%;
transform: translateY(-50%);
width: 150px;
height: 600px;
max-width: 80%;
}
.enplLeaderboard {
min-height: 90px;
min-width: 728px;
}
.sticky-ad iframe {
width: 160px;
height: 600px;
}
.sticky-ad.left {
left: 10px;
}
.sticky-ad.right {
right: 10px;
}
.sticky-ad.right iframe {
position: relative;
right: 10px;
}
@media only screen and (max-width: 1550px) {
.sticky-ad {
display: none;
}
}
/* Ads style box */
.advert-box {
text-align: right;
font-size: xx-small;
padding: 1px;
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
}
.par {
font-size: x-small !important;
}
@media only screen and (max-width: 600px) {
.enplLeaderboard {
min-height: 50px;
min-width: 320px;
}
}
</style>
Example: Sample code to close the road blocker ads
<!-- Iframe removal -->
<script type='text/javascript'>
const eventMethod = window.addEventListener
? 'addEventListener'
: 'attachEvent';
const eventer = window[eventMethod];
const messageEvent = eventMethod === 'attachEvent' ? 'onmessage' : 'message';
const resizeIframe = data => {
const iframesList = document.querySelectorAll(`[id*="${data.iframe}"]`);
const iframeContainer = iframesList[iframesList.length - 1];
const iframeParent = iframeContainer.parentNode;
iframeParent.style.width = data.dimensions[0];
iframeParent.style.height = data.dimensions[1];
iframeContainer.setAttribute('width', data.dimensions[0]);
iframeContainer.setAttribute('height', data.dimensions[1]);
};
const replaceAdContent = data => {
const adUnitsList = document.querySelectorAll(`div[id*="${data.adUnit}"]`);
const adUnitContainer = adUnitsList[adUnitsList.length - 1];
adUnitContainer.innerHTML = data.content;
const scriptTag = document.createElement('script');
scriptTag.innerHTML = data.script;
adUnitContainer.appendChild(scriptTag);
};
// Listen to message from child window
eventer(
messageEvent,
e => {
const { data } = e;
const eventName = data.message;
if (eventName === 'adContentAvailable') {
replaceAdContent(data);
} else if (eventName === 'resizeIframe') {
resizeIframe(data);
}
},
false
);
</script>