Coder Social home page Coder Social logo

Comments (5)

mdenti avatar mdenti commented on July 17, 2024 3

This issue is really old, but I just butted my head on it so I'll write here the solution for anyone looking.

The docs are a bit misleading, but looking at the code here the uid needs to be passed in the options object to work. Alternatively you can use the persistent parameters.

from universal-analytics.

dannytranlx avatar dannytranlx commented on July 17, 2024

I am also looking into this. It looks like the second param is only the cid which isn't the same as User-ID/uid.

@theoephraim did create #35 that addresses #34 for the same issue.

from universal-analytics.

jtillmann avatar jtillmann commented on July 17, 2024

Thanks for the heads-up, just updated to docs.

from universal-analytics.

slidenerd avatar slidenerd commented on July 17, 2024

Same problem still going on now
I am running on express and using this middleware function I wrote for all routes


const analyticsMiddleware = (req, res, next) => {
    const userId = req && req.user && req.user._id ? req.user._id : req.visitor.cid
    var visitor = ua(process.env.GOOGLE_ANAYTICS_TRACKING_ID, userId, { strictCidFormat: false});
    console.log(req.visitor.cid, req && req.user ? req.user._id : '', visitor);
    visitor.pageview(req.path).send();
    next();
}


Always has the incorrect cid , my custom userId from the database looks like this 5d52a69b062d1a150b345712
It is definitely not a UUID but isnt that strictCidFormat supposed to handle this case

If I call visitor.set('uid', '5d52a69b062d1a150b345712') as @mdenti mentioned I get an error saying invalid UUID format
Any ideas?

from universal-analytics.

slidenerd avatar slidenerd commented on July 17, 2024

Update never mind,
I think this works

const analyticsMiddleware = (req, res, next) => {
    const userId = req && req.user && req.user._id ? req.user._id : req.visitor.cid
    req.visitor.set("uid", userId);
    req.visitor.pageview(req.path).send();
    next();
}

from universal-analytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.