Console.log() not appearing in log if I also navigate away

I am attempting to make a log when someone goes to a certain page, but after I make the log, I navigate them away. Unfortunately this prevents the logs from also appearing even though I do the log before the navigation. Is there a way to make this work?

import wixLocation from ‘wix-location’ ;
import wixWindow from ‘wix-window’ ;
$w . onReady ( function () {
// Write your JavaScript here
console . log ( “Site visited from QR code.” );

wixWindow . getCurrentGeolocation () 

. then ( ( obj ) => {
let timestamp = obj . timestamp ; // 1495027186984
let latitude = obj . coords . latitude ; // 32.0971036
let longitude = obj . coords . longitude ; // 34.774391099999995
let altitude = obj . coords . altitude ; // null
let accuracy = obj . coords . accuracy ; // 29
let altAccuracy = obj . coords . altitudeAccuracy ; // null
let heading = obj . coords . heading ; // null
let speed = obj . coords . speed ; // null
console . log ( obj );

[wixLocation](wixLocation.to("myspotify) [.](wixLocation.to("myspotify) [to](wixLocation.to("myspotify) [(](wixLocation.to("myspotify) ["myspotify](wixLocation.to("myspotify) [u]page[/u] " ); 
wixLocation . to ( "/" ); 

} )
. catch ( ( error ) => {
let errorMsg = error ;

});

});

You didn’t mention where you looked for the logs (browser console/site monitoring tool).
So I’d guess you looked in the browser console, and that it did log, but the console got cleared on navigation so you didn’t have time to see it.
If you want to preserve logs on navigation, go the browser dev tools console, click on the settings icon and tick on the Preserve Logs checkbox.

If you were talking about the site monitoring tool, it’s a different matter.

What are you trying to accomplish? What are you trying to do with the logs?

On an unrelated topic, you have two wixLocation.to() statements in sequence. Note that the second one will never execute since the first one already caused a redirection.

So here is what I did to test that everything is working individually.

I am using the Google monitoring tool BTW. I removed both wixLocation.to u [/u] calls. By doing so I was able to see the console.logs in the Google monitoring tool. By adding back the wixLocation.to() calls the console.logs didn’t show up again.

Also having those two wixLocation.to() calls actually worked as intended because one of them opens a new browsers or the Spotify app, while the other navigates inside my own wix page.