Answer the question
In order to leave comments, you need to log in
How to connect the YAN block to a NuxtJs project?
Hello, I saw similar questions, but still need help in solving.
It is necessary to connect the block with advertising (YAN) in the project on NuxtJs.
To do this, I created a separate component,
at the moment its code looks like this
<template>
<!-- Yandex.RTB R-A-643225-1 -->
<div id="yandex_rtb_R-A-643225-1"></div>
</template>
<script>
export default {
mounted() {
(function(w, d, n, s, t) {
w[n] = w[n] || [];
w[n].push(function() {
Ya.Context.AdvManager.render({
blockId: "R-A-643225-1",
renderTo: "yandex_rtb_R-A-643225-1",
async: true
});
});
t = d.getElementsByTagName("script")[0];
s = d.createElement("script");
s.type = "text/javascript";
s.src = "//an.yandex.ru/system/context.js";
s.async = true;
t.parentNode.insertBefore(s, t);
})(this, this.document, "yandexContextAsyncCallbacks");
}
}
</script>
Answer the question
In order to leave comments, you need to log in
Helped koment: ReaverJS @ReaverJS
Error most likely in different contexts of "this".
I think you can change this to window and this.document to document.
Final code:
<template>
<!-- Yandex.RTB R-A-643225-1 -->
<div id="yandex_rtb_R-A-643225-1"></div>
</template>
<script>
export default {
mounted() {
(function(w, d, n, s, t) {
w[n] = w[n] || [];
w[n].push(function() {
Ya.Context.AdvManager.render({
blockId: "R-A-643225-1",
renderTo: "yandex_rtb_R-A-643225-1",
async: true
});
});
t = d.getElementsByTagName("script")[0];
s = d.createElement("script");
s.type = "text/javascript";
s.src = "//an.yandex.ru/system/context.js";
s.async = true;
t.parentNode.insertBefore(s, t);
})(window, document, "yandexContextAsyncCallbacks");
}
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question