Google Analytics: sessionId is not defined



  • Hi
    I am trying to implement GA to my mobile android app and I got stuck at “sessionId is not defined” error:

    Uncaught (in promise) ReferenceError: sessionId is not defined
        at eval (google-analytics.js?91fb:5)
        at eval (vue-router.esm.js?4af9:2176)
        at Array.forEach (<anonymous>)
        at HashHistory.updateRoute (vue-router.esm.js?4af9:2175)
        at eval (vue-router.esm.js?4af9:2037)
        at eval (vue-router.esm.js?4af9:2159)
        at step (vue-router.esm.js?4af9:1843)
        at step (vue-router.esm.js?4af9:1850)
        at step (vue-router.esm.js?4af9:1850)
        at runQueue (vue-router.esm.js?4af9:1854)
    

    in file “google-analytics.js?91fb:5

    import ga from '../analytics.js'
    
    export default ({ router }) => {
      router.afterEach((to, from) => {
        ga.logPage(to.path, to.name, sessionId)
      })
    }
    

    I created everything following tutorial from Quasar help and Multiminds tutorial but I can not figure out why the SessionID is undefined.
    I tried to set it as constant and the result is the same.

    I also installed the app on my cellphone but I can not see any data on Google analytics.

    Does anyone has any idea what am I doing wrong?

    thanks

    A.



  • One more thing, when I deploy SPA app ($ quasar dev) everything works fine and I can see 1 active user in Google Analytics.
    This only happens when I start the app with:
    $ quasar dev -m android



  • I managed to solve my problem, although I still don’t know why it’s not working without this solution.
    So, in order to avoid “sessionId is not defined” error I created a random session ID using uid() function in google-analytics.js instead of sessionID.

    import { uid } from 'quasar'
    import ga from '../analytics.js'
    
    export default ({ router }) => {
      router.afterEach((to, from) => {
        ga.logPage(to.path, to.name,  uid())
      })
    }
    

    I hope this can help someone although I am still not sure if it is the right way as I just recently started to use Quasar and GA



  • Another newbie here, and I found this post when encountering the same issue and your solution only registered the first load of a site. Instead, I recommend you set up Google Tag Manager (which was new to me and is a companion to Google Analytics, but NOT the same) as per the instructions below
    https://fullstack-tutorials.com/quasar-framework/quasar-framework-google-tag-manager-and-analytics-setup-for-an-spa-website

    Takes a little while to set up, and make sure you follow ALL of the instructions but works GREAT


Log in to reply