: Force sending event for sessions without a logged in user Is there any possibility using the Google Analytics API to check if the session is logged in or not? I have a problem with destination
Is there any possibility using the Google Analytics API to check if the session is logged in or not? I have a problem with destination page (it is not set), and I want to resend the event when the session is not logged in.
More posts by @Karen161
3 Comments
Sorted by latest first Latest Oldest Best
You can use something like this
1) Set up onBeforeAction hooks to login the user automatically (which asks for credentials if user is not logged in to external service)
var loginWithGoogle = function() {
if (bla.isClient) {
Session.set('loginError', undefined);
bla.loginWithGoogle({
loginStyle : "redirect",
requestPermissions : ['profile', 'email'],
requestOfflineToken: true
}, function (err) {
if (err)
Session.set('loginError', 'reason: ' + err.reason + ' message: ' + err.message || 'Unknown error');
});
}
}
var requireLogin = function() {
if (! bla.user()) {
if (bla.loggingIn()) {
this.render(this.loadingTemplate);
} else {
console.log('Some crazy stuff');
loginWithGoogle();
}
} else {
this.next();
}
}
Router.onBeforeAction(requireLogin, {except: ['some-special-public-route']});
2) Log the user out when they are navigating away from every page (caveat: login/logout gets called everytime the user navigates within the app)
bla.startup(function(){
$(window).bind('beforeunload', function() {
closingWindow();
});
});
closingWindow = function(){
console.log('You are leaving.');
bla.logout();
}
There should be a request to _utm.gif? from the page. (See this blog post and this SO answer.)
Unfortunately I can't find out if/how it's possible to know if a request has been done from a page. This code is the best I quickly found.
You can force to start a new session in case You need it using the sessionControl. Send a hit like :
ga(‘send’, ‘pageview’, {‘sessionControl’: ‘start’});
Further info developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#sessionControl
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.