Switching to the new ad tag

Since July 20, 2021, Adfox has used the universal ad loader code. Different loader codes were previously used to load different types of Yandex Advertising Network and Adfox units. With the new codes, the browser does not waste time accessing multiple loads, so ads are served faster. The new Adfox banner code is now asynchronous by default and contains a single yaContextCb loading queue, which optimizes loading for 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 tags on the page and make sure that it works properly, and then move on to the next one.

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 Inventory tab and click Ad tag next to the site name.
  • At the placement level: Go to Inventory → Sections → Placements and click Ad tag next to the name of the site.
  • At the banner level: On the Campaigns tab, select a campaign, go to Banners → Placement and click Ad tag next to the desired placement.

To replace the ad tag manually:

  1. Add the ad loader code to the <head> of each page where the ad is displayed:

    <script>window.yaContextCb = window.yaContextCb || []</script>
    <script src="https://yandex.ru/ads/system/context.js" async></script>
    

    Note

    The ad loader code is the same for all types of Yandex ads. If the page already contains separate codes for Yandex Advertising Network units or a 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 code 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 units' tags. If the loader is already in the browser cache when loading the page, the ad tags are run faster.

Sample 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-->
<!--Platform: example.pro / * / *-->
<!--Banner type: 100%х250 -->
<!--Position: <top>-->
<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 the obsolete asynchronous ad tag

If your site uses an 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 code with new code:

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

Send an email