Mobile app version of vmapp.org
Login or Join
Karen161

: 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

@Karen161

Posted in: #Google #GoogleAnalytics #GoogleSearchConsole #Logging #Session

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.

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Karen161

3 Comments

Sorted by latest first Latest Oldest Best

 

@Angela700

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();
}

10% popularity Vote Up Vote Down


 

@Annie201

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.

10% popularity Vote Up Vote Down


 

@Radia820

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme