Switching to the new ad tag

Starting July 20, 2021, Adfox uses the universal ad loader code. Previously, different loader codes were used to load different types of Yandex Advertising Network and Adfox ad units. With the new codes, the browser does not waste time accessing multiple loads, so ads are served faster. The new Adfox banner ad tag is now asynchronous by default and contains a single yaContextCb loading queue: this optimizes loading of different types of ads on the page.

The old ad tags are compatible with the new ones, so you can change the banner codes on the pages of your site gradually. We recommend that you first make changes to one of the ad tags on the page and make sure that it works properly, and then move on to the next one.

  1. Replacing the old ad tag with the new one
  2. Replacing obsolete asynchronous ad tag

Replacing the old ad tag with the new one

You can get the new ad tag in the Adfox interface:

  • At the site level: Open the Sites tab and click next to the site name.
  • At the placement level: Go to Sites → Sections → Placements and click next to the name of the site.
  • At the banner level: On the Campaigns tab, select a campaign, go to Banners → Placements and click next to the desired placement.

To replace the ad tag manually:

  1. Add the ad loader code to the <head> of each page where your ads are served:
    <script>window.yaContextCb = window.yaContextCb || []</script>
    <script src="https://yandex.ru/ads/system/context.js" async></script>
    Copied to clipboard
    Note. The ad loader code is the same for all types of Yandex ads. If the page already contains separate codes of the Yandex Advertising Network ad units or recommendation widget, you don't need to duplicate the ad loader code.
  2. Remove the scripts with the old code loaders from the banner code:
    • <script src="https://yastatic.net/pcode/adfox/loader.js" crossorigin="anonymous"></script>
    • <script src="https://an.yandex.ru/system/adfox.js" crossorigin="anonymous"></script>
    • <script src="https://an.yandex.ru/system/context.js" crossorigin="anonymous"></script>
  3. Add new lines to the banner code:
    window.yaContextCb.push(()=>{
    ...
    })
    Old code New code
    <div id="adfox_162624621735476317"></div>
    <script>
      window.Ya.adfoxCode.create({
        ownerId: 353052,
        containerId: 'adfox_162624621735476317',
        params: { pp: 'g', ps: 'ezwy', p2: 'gnhv' }
      });
    </script>
    <div id="adfox_162624621735476317"></div>
    <script>
      window.yaContextCb.push(()=>{
          Ya.adfoxCode.create({
          ownerId: 353052,
          containerId: 'adfox_162624621735476317',
          params: { pp: 'g', ps: 'ezwy', p2: 'gnhv' }
        })
      })
    </script>
How the new ad tag works
The ad rendering function is no longer called immediately, but is added to a single call queue. When the browser downloads and runs the loader code, it parses the queue and calls the ad block ad tags. If the loader is already in the browser cache when loading the page, the ad tags are run faster.
Example of the new ad tag
<!-- In the site <head>, add the loader code once-->
<script>window.yaContextCb = window.yaContextCb || []</script>
<script src="https://yandex.ru/ads/system/context.js" async></script>

<!--Adfox START-->
<!--login-->
<!--Placement: example.pro / * / *-->
<!--Banner type: 100%х250 Turbo-->
<!--Position: <top of the page>-->
<div id="adfox_16244342575025707"></div>
<script>
  window.yaContextCb.push(()=>{
    Ya.adfoxCode.create({
      ownerId: 353052,
      containerId: 'adfox_16244342575025707',
      params: {
        pp: 'g',
        ps: 'ezwy',
        p2: 'gnhv'
      }
    })
  })
</script>
Note. If you use the Header Bidding code on your site pages, you should change it, too. Learn more about replacing the Header Bidding code

Replacing obsolete asynchronous ad tag

If your site uses obsolete asynchronous ad tag, replace it with the new one.

Code correspondence:

Code type Obsolete code New code
Asynchronous code adfoxAsyncParams Ya.adfoxCode.create
Adaptive code adfoxAsyncParamsAdaptive Ya.adfoxCode.createAdaptive

Examples of replacing obsolete asynchronous ad tag with the new one:

Obsolete code New code
<div id="adfox-id"></div>
<script>
  (function(w, n) {
    w[n] = w[n] || [];
    w[n].push({
      ownerId: 208087,
      containerId: 'adfox-id',
      params: { ... }
    });
  })(window, 'adfoxAsyncParams');
</script>
<div id="adfox-id"></div>
<script>
  window.yaContextCb.push(()=>{
    Ya.adfoxCode.create({
      ownerId: 208087,
      containerId: 'adfox-id',
      params: { ... }
    });
  });
</script>

Contact support