How to get current visitor's information?


#1

How would I retrieve details about the current visitor using Javascript?

Lets say I want to get their location and then write it somewhere on my webpage. For example, I have a headline that says:

“Thanks for visiting us from ENTER THEIR STATE NAME”

I would want to be able to get this info during the page load in javascript/jquery. Something like this:


<h1>Thanks for visiting us from <span id="state"></span>.</h1>

<script type="text/javascript">
$(function(){
    var StateName = Piwik.GetThisVisitorInfo().Location.State; //--- I made this up, but how would I do this part?
   $("#state").text(StateName);
});
</script>

Thanks for any help.


#2

I realize this is old, but for anyone else who’s looking for answers:

var visitorInfo = Piwik.getAsyncTracker().getVisitorInfo();

visitorInfo will be
[bool newvisitor? , visitor ID , profile creation timestamp , number of visits , current visit timestamp , last visit timestamp , last ecommerce order timestamp ]

If you need more info you can get the complete visitor profile by hitting your Piwik server with
module=API&method=Live.getVisitorProfile&visitorId={visitorId}