-- Global site tag gtag js Google Analytics -- script async src https

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-17327728-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-17327728-2');
</script>
<script>
$(document).ready(function () {
if (sessionStorage.getItem("startTime") == null){
var startTime = new Date().getTime();
sessionStorage.setItem("startTime", startTime);
}
if ($('#gag-push').length > 0) {
var endTime = new Date().getTime();
var startedTime = sessionStorage.getItem('startTime');
var timeSpent = (endTime - startedTime);
timeSpent = timeSpent.toFixed();
ga('create', 'UA-17327728-2', 'auto');
ga('send', 'timing', 'Время до конверсии', 'Покупка товара', timeSpent);
console.log('sended');
}
});
</script>