Skip to content

Instantly share code, notes, and snippets.

@dkushnikov
Created September 16, 2013 17:14
Show Gist options
  • Save dkushnikov/6583591 to your computer and use it in GitHub Desktop.
Save dkushnikov/6583591 to your computer and use it in GitHub Desktop.
(function ($, BEM) {
'use strict';
var CHANNEL_NAME = 'statistic';
var CHANNEL_EVENT_HIT = 'hit';
var CHANNEL_EVENT_REACH_GOAL = 'reachGoal';
BEM.DOM.decl({
block: 'i-yandexMetrika'
}, {
params: {
counterId: null,
counterParams: {}
},
apiUrl: '//mc.yandex.ru/metrika/watch.js',
metrika: null,
onSetMod: {
'js': function () {
$.getScript(this.apiUrl, this._proxy(this.initCounter));
}
},
initCounter: function () {
var counterName = 'yaCounter' + this.params.counterId;
//noinspection JSUnresolvedVariable,JSUnresolvedFunction
window[counterName] = this.metrika = new Ya.Metrika({
id: this.params.counterId,
enableAll: true,
webvisor: true
});
this.metrika.params(this.params.counterParams);
//noinspection JSUnresolvedFunction
this.metrika.clickmap({
'mode': 'centered'
});
BEM.channel(CHANNEL_NAME)
.on(CHANNEL_EVENT_HIT, {}, function (e, openData) {
this.processHit(openData.location, openData.title);
}, this)
.on(CHANNEL_EVENT_REACH_GOAL, {}, function (e, reachGoalData) {
this.processReachGoal(reachGoalData.target, reachGoalData.params);
}, this);
},
processHit: function (url, title) {
this.metrika.hit(url, title);
},
processReachGoal: function (target, params) {
this.metrika.reachGoal(target, params || null);
}
});
})(jQuery, BEM);
@dkushnikov
Copy link
Author

Вызов можно делать так:
BEM.channel('statistic').trigger('reachGoal', {target: target, params: params});
или
BEM.channel('statistic').trigger('hit', {location: location, title: title});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment