Created
September 16, 2013 17:14
-
-
Save dkushnikov/6583591 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Вызов можно делать так:
BEM.channel('statistic').trigger('reachGoal', {target: target, params: params});
или
BEM.channel('statistic').trigger('hit', {location: location, title: title});