Search code examples
phpipmixpanel

Setting user ip using Mixpanel PHP library


I'm setting user details using Mixpanel PHP library ($mixpanel->people->set). It works fine, email, registration date etc. are set correctly.

However the location (Country, City, Tomezone) attributes are all wrong. I believe this could be solved by setting the user IP somehow (since we're seding a "hit" from backend and our server IP might be used by default). The problem is Mixpanel API reference doesn't mention this even once.

How can this be achieved? How can I set the IP address for my Mixpanel users?

Thank you


Solution

  • I just found an answer myself.

    Apparently the reference does mention it.

    Set properties on a user record.

    set(string | int $distinct_id, array $props, string | null $ip) If the profile does not exist, it creates it with these properties. If it does exist, it sets the properties to these values, overwriting existing values.

    Parameters

    $distinct_id stringint the distinct_id or alias of a user

    $props array associative array of properties to set on the profile

    $ip stringnull the ip address of the client (used for geo-location)

    So the user IP is the third parameter of the set method.

    The quote if from here