Skip to content

Instantly share code, notes, and snippets.

@Kiryous
Created April 26, 2016 12:28
Show Gist options
  • Save Kiryous/8838bd71e84c9c09c6aa05f744ea3dbf to your computer and use it in GitHub Desktop.
Save Kiryous/8838bd71e84c9c09c6aa05f744ea3dbf to your computer and use it in GitHub Desktop.
jquery.scrolldepth-settings.js
function send2carrot(str) {
// Отправляет данные в CarrotQuest
var eventName = str.eventAction + " " + str.eventLabel;
if (pages.length > 1) eventName = currentPage + " / " + eventName;
carrotquest.track(eventName, {
action: str.eventAction,
trigger: str.eventLabel,
distance_in_px: str.eventDistance,
time_in_sec: str.eventTiming
});
// Выводит в консоль данные
if ( typeof console !== 'undefined' && typeof console.log !== 'undefined' ) {
console.log(str);
}
}
// Эта функция проверяет, входит ли текущая страница в список разрешенных
function checkPage()
{
var url = document.URL;
url = url.replace("http://", "");
url = url.replace("https://", "");
url = url.split("?")[0];
for (var i = pages.length - 1; i >= 0; i--) {
if (url == pages[i][0]) {
currentPage = pages[i][1];
console.log("Page selected > " + currentPage);
}
};
}
//////////////////////////////////////////////////////////////////////////////////////////////
// НАСТРОЙКА И ЗАПУСК СКРИПТА
// Список страниц, на которых будет запускаться скрипт
var pages = [
["promo.zemaktiv.ru/", "Промо"],
["promo.zemaktiv.ru/bereg-v/", "Берег"],
["promo.zemaktiv.ru/bereg-v-plus/", "Берег Плюс"],
];
var currentPage = "";
checkPage();
// В elements нужно добавлять селекторы для отслеживаемых блоков
$.scrollDepth({
elements: ['#js-footer', '#js-excursion'],
eventHandler: function(data) {
if (currentPage != "") send2carrot(data)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment