ym() {
return (
"<script src='https://mc.yandex.ru/metrika/watch.js' type='text/javascript'></script>\
<script type='text/javascript'>\
try {\
var yaCounterXXXXX = new Ya.Metrika({\
id:XXXXX,\
clickmap:true,\
trackLinks:true,\
accurateTrackBounce:true,\
webvisor:true,\
trackHash:true\
});\
} catch(e) { }\
</script>"
);
},
<div dangerouslySetInnerHTML={{__html: this.ym()}}/>
import { YMInitializer } from 'react-yandex-metrika';
class MyComponent extends React.Component {
render() {
return (
<div>
// SNIP
<YMInitializer accounts={[987654321]} />
// SNIP
</div>
);
}
});
// И потом используем так:
import ym from 'react-yandex-metrika';
ym('hit', '/cart');
ym('reachGoal', 'whateverGoal', {awesomeParameter: 42});
class MetricContainer extends Component {
render() {
return <div dangerouslySetInnerHTML={{__html: someHtmlStringFromServer}}/>
}
}