From 05ce062d5bf4ef92e222b118f393bd843e947c89 Mon Sep 17 00:00:00 2001 From: Mikhail Troshev Date: Wed, 28 Jul 2021 22:07:17 +0300 Subject: [PATCH] Update Yandex & ADFOX amp-ad codes --- ads/_config.js | 6 ++-- ads/vendors/adfox.js | 43 ++++++---------------------- ads/vendors/yandex.js | 65 +++++++++++++++++++------------------------ 3 files changed, 41 insertions(+), 73 deletions(-) diff --git a/ads/_config.js b/ads/_config.js index f60c11b127f9c..703b970673f63 100755 --- a/ads/_config.js +++ b/ads/_config.js @@ -116,7 +116,8 @@ const adConfig = jsonConfiguration({ 'adform': {}, 'adfox': { - prefetch: 'https://yastatic.net/pcode/adfox/loader.js', + prefetch: 'https://yandex.ru/ads/system/context.js', + preconnect: ['https://yastatic.net/'], renderStartImplemented: true, }, @@ -1363,7 +1364,8 @@ const adConfig = jsonConfiguration({ }, 'yandex': { - prefetch: 'https://an.yandex.ru/system/context_amp.js', + prefetch: 'https://yandex.ru/ads/system/context.js', + preconnect: ['https://yastatic.net/'], renderStartImplemented: true, }, diff --git a/ads/vendors/adfox.js b/ads/vendors/adfox.js index f0e95622c4d04..5b35d66cab092 100644 --- a/ads/vendors/adfox.js +++ b/ads/vendors/adfox.js @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import {loadScript, validateData} from '#3p/3p'; -import {yandex} from './yandex'; /** * @param {!Window} global @@ -23,55 +21,30 @@ import {yandex} from './yandex'; */ export function adfox(global, data) { validateData(data, ['adfoxParams', 'ownerId']); - loadScript(global, 'https://yastatic.net/pcode/adfox/loader.js', () => - initAdFox(global, data) + loadScript(global, 'https://yandex.ru/ads/system/context.js', () => + renderAdFox(global, data) ); } /** * @param {!Window} global - * @param {Object} data + * @param {!Object} data */ -function initAdFox(global, data) { - const params = JSON.parse(data.adfoxParams); +function renderAdFox(global, data) { + const renderTo = 'adfox_container'; - createContainer(global, 'adfox_container'); + createContainer(global, renderTo); global.Ya.adfoxCode.create({ ownerId: data.ownerId, - containerId: 'adfox_container', - params, - onLoad: (data, onRender, onError) => { - checkLoading(global, data, onRender, onError); - }, + containerId: renderTo, + params: JSON.parse(data.adfoxParams), onRender: () => global.context.renderStart(), onError: () => global.context.noContentAvailable(), onStub: () => global.context.noContentAvailable(), }); } -/** - * @param {!Window} global - * @param {!Object} data - * @param {!Object} onRender - * @param {!Object} onError - * @return {boolean} - */ -function checkLoading(global, data, onRender, onError) { - if (data.bundleName === 'banner.direct') { - const dblParams = { - blockId: data.bundleParams.blockId, - data: data.bundleParams.data, - onRender, - onError, - }; - - yandex(global, dblParams); - return false; - } - return true; -} - /** * @param {!Window} global * @param {string} id diff --git a/ads/vendors/yandex.js b/ads/vendors/yandex.js index baab4f6a843b2..c58b78ee17732 100644 --- a/ads/vendors/yandex.js +++ b/ads/vendors/yandex.js @@ -15,54 +15,47 @@ */ import {loadScript, validateData} from '#3p/3p'; -const n = 'yandexContextAsyncCallbacks'; -const renderTo = 'yandex_rtb'; - /** * @param {!Window} global * @param {!Object} data */ export function yandex(global, data) { validateData(data, ['blockId'], ['data', 'onRender', 'onError']); - - addToQueue(global, data); - loadScript(global, 'https://an.yandex.ru/system/context_amp.js'); + loadScript(global, 'https://yandex.ru/ads/system/context.js', () => + renderYandex(global, data) + ); } /** * @param {!Window} global * @param {!Object} data */ -function addToQueue(global, data) { - global[n] = global[n] || []; - global[n].push(() => { - // Create container - createContainer(global, renderTo); +function renderYandex(global, data) { + const renderTo = 'yandex_rtb'; - // Show Ad in container - global.Ya.Context.AdvManager.render( - { - blockId: data.blockId, - statId: data.statId, - renderTo, - data: data.data, - async: true, - onRender: () => { - if (typeof data.onRender === 'function') { - data.onRender(); - } - global.context.renderStart(); - }, - }, - () => { - if (typeof data.onError === 'function') { - data.onError(); - } else { - global.context.noContentAvailable(); + createContainer(global, renderTo); + + global.Ya.Context.AdvManager.render( + { + blockId: data.blockId, + statId: data.statId, + renderTo, + data: data.data, + onRender: () => { + if (typeof data.onRender === 'function') { + data.onRender(); } + global.context.renderStart(); + }, + }, + () => { + if (typeof data.onError === 'function') { + data.onError(); + } else { + global.context.noContentAvailable(); } - ); - }); + } + ); } /** @@ -70,7 +63,7 @@ function addToQueue(global, data) { * @param {string} id */ function createContainer(global, id) { - const d = global.document.createElement('div'); - d.id = id; - global.document.getElementById('c').appendChild(d); + const container = global.document.createElement('div'); + container.setAttribute('id', id); + global.document.getElementById('c').appendChild(container); }