GithubHelp home page GithubHelp logo

davyjohnes / react-yandex-metrika Goto Github PK

View Code? Open in Web Editor NEW

This project forked from narkq/react-yandex-metrika

0.0 2.0 0.0 255 KB

React component for Yandex.Metrika

Makefile 11.35% JavaScript 88.65%

react-yandex-metrika's Introduction

react-yandex-metrika

Adds the Yandex.Metrika script to your page and exposes the ym tracking function as a module.

Inspired by and shamelessly copied from react-google-analytics.

Usage:

Use the initializer to add the script to your page somewhere:

import { YMInitializer } from 'react-yandex-metrika';

class MyComponent extends React.Component {
  render() {
    return (
      <div>
        // SNIP
          <YMInitializer accounts={[987654321]} />
        // SNIP
      </div>
    );
  }
});

Please note that you need to initialize the tracker object only once. Because of that, you should insert initializer to the place where it won't be remounted (that means at least outside of router scope).
If you want to use webvisor, you should pass options={{webvisor: true}} to to YMInitializer, for example:

<YMInitializer accounts={[987654321]} options={{webvisor: true}}/>

You can create several identical trackers (that might be useful for domain-wise segmentation).

<YMInitializer accounts={[98765, 4321]} />

You can also specify options for tracker (as described in Yandex.Metrika documentation):

<YMInitializer accounts={[98765]} options={{defer: true}} />

Elsewhere, use the ym function:

import ym from 'react-yandex-metrika';
ym('hit', '/cart');
ym('reachGoal', 'whateverGoal', {awesomeParameter: 42});

Webvisor 2.0 support

See #6 for details.

<YMInitializer accounts={[31337]} options={{webvisor: true}} version="2" />

Migration from 1.0

  • Replace import { Initializer } to import { YMInitializer }.
  • Remove ym.init() call. Pass arguments of ym.init as props to the YMInitializer component. Tracking will be initialized on YMInitializer.componentDidMount.

react-yandex-metrika's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.