Giter Site home page Giter Site logo

yandex_metrika's Introduction

Yandex.Metrika [ru]

(skip to next chapter for description in English)

Установка

Добавьте в config/environment.rb:

config.gem "yandex_metrika", :lib => "yandex/metrika", :source => "http://gemcutter.org"

и выполните команду:

rake gems:install

Описание

Быстрая интеграция Яндекс.Метрики в ваше Rails-приложение.

По умолчанию код метрики автоматически вставляется в каждую страницу перед закрывающим тэгом </body>. Но сначала нужно корректно сконфигурировать плагин, иначе он будет ругаться.

Конфигурация

Для этого добавьте следующий код в config/environment.rb:

if defined?Yandex::Metrika
    Yandex::Metrika.counter_id = '123456'
end

А для избежания замусоривания environment.rb всякими плагинами - можно добавить этот конфиг в config/initializers/yandex_metrika.rb

Вместо ‘123456’ нужно вставить ваш личный COUNTER_ID, который можно вытащить из javascript-кода, предоставляемого Яндексом: “new Ya.Metrika(123456)”, тут 123456 и есть искомый код.

По умолчанию код метрики вставляется в страницы только при использовании production окружения. Для активации кода и в development нужно сделать так:

Yandex::Metrika.environments = %w'production development'

Если есть необходимость для каких-то страниц выключить код Яндекс.Метрики - то добавть следующий код в соответствующий класс контроллера:

skip_after_filter :add_yandex_metrika_code

Yandex.Metrika [en]

This plugin enables Yandex.Metrika support in your application. By default it will output the metrika code for every single page automatically, if it is configured correctly. This is done by adding:

Yandex::Metrika.counter_id = '123456'

to your config/environment.rb, inserting your own COUNTER_ID. This can be discovered by looking at the value of “new Ya.Metrika(123456)” in the Javascript code.

If you want to disable the code insertion for particular pages, add the following to controllers that don’t want it:

skip_after_filter :add_yandex_metrika_code

If you are running rails 2.1 or above add install this by adding:

config.gem "yandex_metrika", :lib => "yandex/metrika", :source => "http://gemcutter.org"

and run:

rake gems:install

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but

    bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Andrey “Zed” Zaikin. See LICENSE for details.

yandex_metrika's People

Contributors

zed-0xff avatar

Watchers

 avatar  avatar

Forkers

timurkhafizov

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.