Last active
May 18, 2022 06:27
-
-
Save ArtemSites/9b88918bc47717d4c231d83141ecfccc to your computer and use it in GitHub Desktop.
Событие: пользователь провёл на сайте заданное время | Event: the user spent the specified time on the site
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
/** | |
* @description: Событие: пользователь провёл на сайте заданное время | Event: the user spent the specified time on the site | |
* @version: v1.1, 09.08.2021 | |
* @author: Artem Kuznecov, web.master-artem.ru | |
* @cacher: https://snippets.cacher.io/snippet/4a2daee81c7ea7033007 | |
**/ | |
(function(){ | |
var targetMoreThenS = 30; | |
var nameEvent = 'timeMoreThen30s'; | |
var ymID = 1111111; | |
var openDateS = Math.round(new Date() / 1000);//seconds instead of milliseconds | |
if ( !localStorage.getItem('timeOpenSiteS') ) { | |
localStorage.setItem('timeOpenSiteS', openDateS); | |
} | |
if ( !localStorage.getItem(nameEvent) ) { | |
localStorage.setItem(nameEvent, false); | |
} | |
if ( localStorage.getItem(nameEvent) == 'false' ) { | |
var timeSDetectInterval = setInterval(function(e) { | |
var curDateS = Math.round(new Date() / 1000); | |
if (curDateS > (Number(localStorage.getItem('timeOpenSiteS')) + targetMoreThenS) ) { | |
ym(ymID, 'reachGoal', nameEvent); | |
localStorage.setItem(nameEvent, true); | |
clearInterval(timeSDetectInterval); | |
} | |
}, 500); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment