Answer the question
In order to leave comments, you need to log in
How to fix this code so that a report is generated with the correct information in Yandex Metrica?
Good day to all! Help fix. Very necessary. There is a site with a Yandex counter code for js installed on it:
<!-- Yandex.Metrika counter -->
<script type="text/javascript">
(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
try {
w.yaCounter20722519 = new Ya.Metrika({
id:20722519,
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true,
trackHash:true,
ecommerce:"dataLayer"
});
} catch(e) { }
});
var n = d.getElementsByTagName("script")[0],
s = d.createElement("script"),
f = function () { n.parentNode.insertBefore(s, n); };
s.type = "text/javascript";
s.async = true;
s.src = "https://mc.yandex.ru/metrika/watch.js";
if (w.opera == "[object Opera]") {
d.addEventListener("DOMContentLoaded", f, false);
} else { f(); }
})(document, window, "yandex_metrika_callbacks");
window.dataLayer = window.dataLayer || [];
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/20722519" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
<script>
function add_ecommerce() {
window.dataLayer.push({
"ecommerce": {
"add": {
"products": [
{
"id": "{GOODS_ID}",
"name": "{GOODS_NAME}",
"price": {GOODS_MOD_PRICE_NOW},
"quantity": $('.quantity').val()
}
]
}
}
});
}
$(document).ready(function(){
$('.add-cart.btn.btn-success.available-now').click(function(){
add_ecommerce()
});
});
</script>
<script>
function add_detail() {
window.dataLayer.push({
"ecommerce": {
"purchase": {
"actionField": {
"id" : "{ORDER_NUM}",
},
"products":[ {%FOR order_lines%}
{% IFNOT order_lines.TYPE_ID=2 %}
{ "id": "{order_lines.MOD_ID}",
"name" : "{order_lines.NAME}",
"price": {order_lines.LINE_PRICE},
"quantity": {order_lines.QUANTITY}
}{%IF order_lines.last%}{%ELSE%},{%ENDIF%}{%ENDIF%}
{%ENDFOR%}
]
}
}
});
}
$(document).ready(function(){
add_detail();
});
</script>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question