Quantcast
Channel: Piwik Forums - Support & Bugs
Viewing all articles
Browse latest Browse all 13117

Re: Extract visitorId from Cookie value of _pk_uid

$
0
0
Hey,

that's funny; for every step and approach I am trying to get browser based and backend REST based user tracking to work, I always come back to that ticket :?

Happily that all works for me now. I was able to extract the visitor ID from the _pk_uid cookie value.
Using this visitor ID in the REST call, by setting parameters cid and _id lets piwik correctly determine that these tracking events belong to a visitor that was previously tracked by the Javascript tracker.

My solution is implemented in Java:

        // example input
        String input = "0%3DczoxNjoiODUzM2ExYTQyYjJmNzgxZSI7%3A_%3D054a6e6d4514a69e3a55fd95440da6b8631f0202";

        String urlDecoded = java.net.URLDecoder.decode(input, "UTF-8");
        String base64Encoded = urlDecoded.substring(urlDecoded.indexOf("0=")+2, urlDecoded.indexOf(":"));
        String base64Decoded = new String(org.apache.commons.net.util.Base64.decodeBase64(base64Encoded));
        String piwikVisitorId = base64Decoded.substring(base64Decoded.indexOf("\"")+1, base64Decoded.lastIndexOf("\""));

Best regards
Tom

Viewing all articles
Browse latest Browse all 13117

Trending Articles