JavaScript (Standalone) Integration accounts for content that loads or changes dynamically. All site builds are able to benefit from this method integration, however additional configuration is required for those sites that utilize dynamic content versus those that do not. This article details some of the additional set-up steps needed to get ads to show for sites that do contain this type of content. However, please note that it is required that you first follow the steps found at https://support.ezoic.com/kb/article/javascript-standalone-integration, otherwise the below steps will not work (please note that sites that have a mix of static and dynamic content, and want to make use of all of Ezoic's features (e.g. Site Speed, SEO), while using the client-side code snippet to call for ads, may prefer to use Hybrid Integration instead. See https://support.ezoic.com/kb/article/hybrid-integration for further instructions).
Changing Pages
When switching between pageviews dynamically, it is important to re-call:
Calling this function following a change to the URL will force ads to refresh on the new page.
New Content
For additional placeholders within the same pageview, you can use the ezstandalone.showAds
function.
If a user scrolls down the page, new content loads, and placeholders 104
and 105
are added, ezstandalone.showAds
should be used to display them.
<script>
ezstandalone.cmd.push(function() {
// call new placeholders
ezstandalone.showAds(104, 105);
});
</script>
Changing content
If the content changes within the same pageview and a placeholder is no longer needed or visible, the placeholder needs to be properly cleaned up using ezstandalone.destroyPlaceholders
. This allows the placeholder to be loaded again via ezstandalone.showAds
if necessary.
<script>
window.ezstandalone.cmd.push(function() {
// destroy placeholders
ezstandalone.destroyPlaceholders(104, 105);
});
</script>
Infinite Scroll
For sites which implement an infinite scroll, a combination of calling ezstandalone.destroyPlaceholders
followed by ezstandalone.showAds
may be necessary to reuse placeholders if within the same pageview.
It is recommended to create a set of in-content
placeholders specifically for infinite scroll.
Example
The example below shows the flow of an infinite scroll would look like on a site with multiple articles.
Start off by calling the placeholder for the first article on page load.
<script>
window.ezstandalone = window.ezstandalone || {};
ezstandalone.cmd = ezstandalone.cmd || [];
ezstandalone.cmd.push(function() {
ezstandalone.showAds(102, 103, 104);
});
</script>
User then scrolls to the next article, so the next set of ads are loaded.
<script>
window.ezstandalone.cmd.push(function() {
// call new placeholders
ezstandalone.showAds(105, 106);
});
</script>
User then scrolls to the third article, and the placeholders from the first article need to be reused.
<script>
window.ezstandalone.cmd.push(function() {
// destroy initial placeholders
ezstandalone.destroyPlaceholders(102, 103, 104);
// call new placeholders
ezstandalone.showAds(102, 103, 104);
});
</script>
Removing all placeholders
Remove all placeholders on the page by using the destroyAll
function
<script>
window.ezstandalone.cmd.push(function() {
ezstandalone.destroyAll();
});
</script>
Show all placeholders
You can call ads in every placeholder on a given page by using the showAds
function, without defining any value.
<script>
window.ezstandalone.cmd.push(function() {
ezstandalone.showAds();
});
</script>