Last active
May 18, 2022 06:34
-
-
Save h-roman/bbd083ef22b057762be565f7ba6719ea to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Цели метрики | |
* Область видимости функции должна быть ГЛОБАЛЬНОЙ | |
*/ | |
slTarget=function (targetName) { | |
if(Ya===undefined) {console.error('Не найден счетчик метрики'); return false;} | |
var counterID=Ya.Metrika2.counters()[0].id; | |
ym(counterID, 'reachGoal',targetName); | |
console.info('Событие: '+targetName); | |
} | |
/** | |
* Примеры | |
*/ | |
// в JS просто вызываем в AJAX.success | |
// slTarget('#НАЗВАНИЕ_ЦЕЛИ#') | |
// В лоб, прямов HTML на onsubmit | |
// <form action="<?=POST_FORM_ACTION_URI?>" method="POST" class="formSubscribe" onsubmit="slTarget('#НАЗВАНИЕ_ЦЕЛИ')"> | |
This file contains 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
slYaGoals=function (targetName) { | |
if(!targetName) { console.error('slYaGoals: Ошибка - не указана цель'); return false}; | |
if(typeof Ya != 'object') { console.error('slYaGoals: Ошибка - не найден счетчик'); return false}; | |
if(typeof ym != 'function') { console.error('slYaGoals: Ошибка - не найдена функция "ym"'); return false}; | |
let counters=Ya.Metrika2.counters(); | |
counters.forEach( counter => { | |
ym(counter.id,'reachGoal',targetName); | |
console.info('slYaGoals: Счетчик ['+counter.id+'] - Цель "'+targetName+'" достигнута.') | |
}); | |
}; | |
// Скопирован адрес в шапке | |
// $('.header-top .address').bind({ | |
// copy : function(){ | |
// slYaGoals('copy_header_address'); | |
// }, | |
// }); | |
// $(document).on("copy",'.information-contact address',function(){ | |
// slYaGoals('copy_address'); | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment