Api ip

Hello,

I’m using the api to track visitors, however there’s a problem that the api is recording the server ip and not the visitor ip.

Can someone please tell me what I can modify to fix this until update?

what file do I need to edit? or what piece of code?

Any help would be greatly appreciated.

Thank you

This is a known problem please search before posting.

This will be fixed in 1.3 or 1.4

I did search, not even this post came up. If there’s info to fix, please just give me a link or something… What I did come across was the same kind of answer by goog search… “This is a known problem” and there’s a ticket. But I haven’t found info for temp fix.

Found a solution… a combination of a solution found in another thread with a separate change to get it working. I’m not sure at this point if it’s the best solution or if its a bad one. But on live visitors it’s now at least showing the ip of the visitor.

in piwiktracker api class

Find:


$url = self::$URL .
	 		'?idsite=' . $idSite .

and add this:


'&my_ip=' . $_SERVER['REMOTE_ADDR'] .

so should look like:


$url = self::$URL .
	 		'?idsite=' . $idSite .
			'&my_ip=' . $_SERVER['REMOTE_ADDR'] .
........

then in core/Common.php

Find:


		// default
		if(isset($_SERVER['REMOTE_ADDR']))
		{
			return self::getFirstIpFromList($_SERVER['REMOTE_ADDR']);
		}

replace with


		// default
		if(isset($_REQUEST['my_ip']))
		{
			return self::getFirstIpFromList($_REQUEST['my_ip']);
		}

Hope it helps someone else facing the same issue.

I can’t find anywhere
// default
if(isset($_SERVER[‘REMOTE_ADDR’]))
{
return self::getFirstIpFromList($_SERVER[‘REMOTE_ADDR’]);
}

It’s not working :frowning:

NOTE: this was implemented in 1.2 !!! see the functions setIp and set date time, now requiring a call to setTokenAuth with the super user API Token to set IP and date.

I’ve started with a fresh install of 1.2 and I cannot get it to work based off info here at piwik.

Would you provide a simple step list to get this working? Where do I get the right token?
I saw info in a ticket that this was unclear has nothing to do with adding a user.

http://dev.piwik.org/trac/ticket/1766

I’ve updated the code snippet in: Tracking API - Analytics Platform - Matomo

does it help?

Thanks for the response. That link is not working, however.

The link works for me.

Yes link is working now. Thanks

I dont know whats been updated. I see no additional info on where to get the $token_auth value.

the token_auth is found in your API page in Piwik, when logged as super user

Finally found it! I was all over the settings area… :slight_smile: Thanks

Clear cut: Token Auth is found by clicking API on the very top of your piwik stats area. :slight_smile: