Hot to set session timeout?
01Kuzma opened this issue · comments
Hi there!
Thank you for you module!
I'd like to know hot to set the session timeout with ES6?
Now I make it in such way:
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o)
, m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-xxx-1', 'auto');
ga('send', 'pageview');
setTimeout(function() {
ga("send", "event", "New Visitor", location.pathname)
}, 15000);
</script>
Hey, can you describe in more detail what you're trying to achieve?
Session timeout (= after what time of inactivity the user's session is ended and next events count as a new session) is commonly set in the Google Analytics' admin panel
Here's a screenshot of the admin panel from my personal blog's analytics, where I have set the session timeout to 30 minutes:
Sorry, I've described it without proper details:
I mean the minimum time which user should remain on website in order to count it as session.
In my GA settings it's 15seconds:
ga('send', 'pageview');
setTimeout(function() {
ga("send", "event", "New Visitor", location.pathname)
}, **15000**);
Ah, I see!
You can use ga-lite exactly the same way in this case as you would in the official Google Analytics: Just replace the ga
with galite
:
galite('create', 'UA-xxx-1', 'auto');
galite('send', 'pageview');
setTimeout(function() {
galite("send", "event", "New Visitor", location.pathname)
}, 15000);
Understood, thank you!
Just one problem left.
I'm using react and I've placed this code in index.js:
...
import galite from 'ga-lite';
class App extends React.Component {
componentWillMount() {
galite('create', 'UA-xxx-1', 'auto');
galite('send', 'pageview');
setTimeout(function() {
galite("send", "event", "New Visitor", location.pathname)
},
}
...
And google tag assistant throws me this error:
No HTTP response detected
Have I done something wrong?
Google Tag Assistant probably does not detect ga-lite, since ga-lite is not officially supported by Google (although the API endpoint ga-lite uses is).
You should see requests to www.google-analytics.com happening in your browser's developer tools' "Network" tab for each event/pageview that you send:
If you see your session at Google analytics realtime, you can be 100% sure your code works and the events are firing fine. Good job! 👌
P.S. press "all" in your network tab and you'll see the Google analytics calls there too. Now it shows only the js files.
Thank you very much!