A
A
Artem Vasiliev2017-04-04 14:40:43
JavaScript
Artem Vasiliev, 2017-04-04 14:40:43

Yandex.Metrika and react-router. How to decide?

The essence of the question is this: there is a SPA application, to which the code of the same metric with parameters is connected to the static index.html file:

new Ya.Metrika({
            id:xxx, 
            clickmap:true,
            trackLinks:true,
            accurateTrackBounce:true,
            webvisor:true,
            trackHash:true 
        })

The webvisor counts clicks and other actions, but only the URL changes, nothing changes in the webvisor itself, the same first page remains.
I found components of the "react-ym" type, but did not understand why they are needed. Or just they solve this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Razzwan, 2017-11-03
@Razzwan

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';
history.listen((location) => {
  ym('hit', localhost.pathname);
})

Taken from here: https://github.com/narkq/react-yandex-metrika

E
Eugene Im, 2017-04-05
@ImEugene

There is the following implementation:

<Router
    ...
    onUpdate={logPageView}
/>

Where logPageView is a function in which you implement logging for Yandex.Metrica/Google Analytics, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question