Code Injection SyntaxError in adminApi.ts

I am trying to add Yandex.Metrika JS script to the website through Code Injection. As a result, errors appear in the chrome console.
Error parsing event data SyntaxError: Unexpected token ‘_’, “__ym__prom”… is not valid JSON
at JSON.parse ()
at adminApi.ts:15:25
Why does adminApi.ts interact with the counter code and how can this be fixed?

Can you share the code you injected? It seems like there might’ve been a syntax error with it.

<!-- Yandex.Metrika counter --> <script type="text/javascript"> (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; m[i].l=1*new Date(); for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }} k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym"); ym(40107620, "init", { clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true }); </script> <noscript><div><img src="upload://xspAPEnjaGTMynnpZt5IwvyRs90.gif" style="position:absolute; left:-9999px;" alt=""></div></noscript> <!-- /Yandex.Metrika counter --> 

It seems like you may be injecting code into the <head> area that expects to go in the <body> area.

Try injecting the code into the “site footer” area, which is in the <body> instead of the “site header”.

See also: How to use Code Injection in Ghost

I tried adding code to the footer, but the same error occurred
https://hostcollate.com/web-server-debian-ubuntu-centos/

I can see, as mentioned, that Ghost’s AdminAPI script is intercepting Yandex events and printing an error because the data isn’t what Ghost expects. Ghost logs the error but site functionality isn’t disrupted.

All of that doesn’t seem to interfere with the Yandex tracking script. I can see it sending data after every click/mouse movement. Is the tracking script not working?

Yes, Yandex tracking is working

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.