Help retreaving values using javascript client api


(Joseph) #1

anyone who can help,

Hi ,
Need help to understand how to get a value using Piwik finctions (like getVisitorId, getCustomeDimentions etc…?

This is the code I have used

var visitor_id;
_paq.push([ function () { visitor_id = this.getVisitorId(); }]);
console.log(visitor_id);

My console keep showing that the variable is undefined.

If I change the code to

var visitor_id;
_paq.push([ function () { visitor_id = this.getVisitorId(); console.log(visitor_id); }]);

cosole will show the correct ID.
I need to to access the visitor_ID variable later on in the script.

I know this is not strictly a piwik/motomo question. But I’m a nube at javascripts and would apreciate any help.

Joseph


(Roddy A. Stegemann) #2

I am responding to your entry, because I am surprised that the phrase this.getVisitorId() returns the Visitor ID.

I am also responding because I am confused by your objective. Under the assumption that the purpose of the _paq array is to gather and send site information to the Matomo server, why are you using it to collect information from same?

Roddy

I am no longer surprised, as it appears that you can use the _paq array to trigger custom function calls to the Matomo server – something that I have yet to do, but might very well save me an HTTP call with cURL in a different context.


(Joseph) #3

Hi @Kiusau,
Thank you for your response. My objective with this project is to track users who visit our site from our email newsletters. I include our unique customer ID in to the email url parameters. Which gets passed on to motomo using javascript client in the landing page. Problem is tracking the users movement within the site once they leave the landing page. So we have created custom dimension to save off the user id in the landing page. Then in every other page we plan to check if the custom dimension exists in the session and set that to user ID . If the custom dimension does not exist, we would use the visitor ID as the user id. At least this is what we are trying to achieve.

The code I have used is taken off the motomo javascript client user guide. JavaScript Tracking Client: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3

Currently I’m not able to figure out how to get the values of custom dimension / visitor ID back from motomo (or the local cookie , wherever the values are stored).

Like I mentioned in the original post with visitor ID, I’m able to get the value inside the function. Just can’t find away to access it later down in my code.
Any suggestions ?

If possible, can you give me a sample of how you use HTTP call to retrieve custom variables/userID/dimensions ? Just want to have a fall back option if the original idea does not work.
Sorry if I’m asking basic questions. I’m a complete nube at this.

Cheers,
Joseph


(Roddy A. Stegemann) #4

If you use a custom variable, rather than a custom dimension, you can retrieve the custom variables for each current visitor using, say

?module=API&method=Live.getVisitorProfile&idSite=1&format=JSON&token_auth=[…]

I have yet to work with custom dimensions.

Roddy

p.s. Browsing the Reporting API methods resulted in the following two additional methods that will likely be of interest to you.

CustomDimensions.getCustomDimension
CustomDimensions.getConfiguredCustomDimensions


(Joseph) #5

Thanks Roddy,
I think I might work with the Http api you provided. For now we have decided to implement a cookie to hold the info and use custom dimensions to tie the analytics together.

Will let you know we manage to churn up something useful. :slight_smile:

Cheers,
Joseph

PS: apologies for the delay in response. Had to jump in to another project that was way past due date.