【发布时间】:2017-04-29 16:44:58
【问题描述】:
我有一个 Meteor 应用程序,所有 UI 组件都是用 React 构建的。我使用 FlowRouter 进行路由。
现在我想使用 Yandex.Metrika 服务添加分析。
我为 React 找到了这个包:https://github.com/narkq/react-yandex-metrika
可是我要怎么用呢?为什么我需要此示例中的 <YM /> 组件?
import {Initializer as YM} from 'react-yandex-metrika';
// Use the initializer to add the script to your page somewhere.
var MyComponent = React.createClass({
render: function() {
return (
<div>
// SNIP
<YM />
// SNIP
</div>
);
}
});
我应该在哪里初始化跟踪器对象?我读到了:
// This is supposed to be executed only in browser and only once.
// Because of that, the most sensible place for this code is right after you javascript bundle.
ym.init([987654321]);
但什么是 javascript 包,我应该将我的 im.init(id) 代码放在哪里?
其实我所需要的只是将数据发送到 Metrika 的功能,例如hit (pageview 模拟 rom ga)、reachGoal 等等。
感谢您的回答!
【问题讨论】:
标签: reactjs meteor web-analytics flow-router yandex-metrika