Created
March 8, 2017 18:16
-
-
Save stiig/dc8428d862c02d28c46830adb6aeff69 to your computer and use it in GitHub Desktop.
Counter for turbolinks with yandex metrika
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 (d, w, c) { | |
(w[c] = w[c] || []).push(function () { | |
try { | |
w.yaCounter99999999 = new Ya.Metrika({ | |
id: 99999999, | |
clickmap: true, | |
trackLinks: true, | |
accurateTrackBounce: true, | |
webvisor: true | |
}); | |
} catch (e) { | |
} | |
}); | |
var n = d.getElementsByTagName("script")[0], | |
s = d.createElement("script"), | |
f = function () { | |
n.parentNode.insertBefore(s, n); | |
}; | |
s.type = "text/javascript"; | |
s.async = true; | |
s.src = "https://mc.yandex.ru/metrika/watch.js"; | |
if (w.opera == "[object Opera]") { | |
d.addEventListener("DOMContentLoaded", f, false); | |
} else { | |
f(); | |
} | |
})(document, window, "yandex_metrika_callbacks"); | |
$(document).on('turbolinks:before-visit', function () { | |
window.turbolinks_referer = location.href; | |
}); | |
$(document).on('turbolinks:load', function () { | |
if (window.turbolinks_referer) { | |
// yandex metrika | |
if (window.yaCounter99999999) { | |
window.yaCounter99999999.hit(location.href, $('title').html(), window.turbolinks_referer); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment