Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am using Google Analytics to track visitors of my website. I also want to track IP address of the visitor but Google doesn't allow this. Now I am thinking that I must save IP address of the visitor on my database before sending visit information to Google Analytics. So when I retrieve information I can glue the IP address with visit information.

But when I query to Google Analytics using following code:

   $optParams = array(
        'dimensions' => 'ga:browser,ga:fullReferrer,ga:source,ga:keyword,ga:campaign,ga:customVarValue1,ga:customVarValue2'
        );
    return $analytics->data_ga->get(
            'ga:' . $profileId, '2013-07-16', '2013-07-20', 'ga:visits',$optParams); 

It is returning data like this:

[rows] => Array
    (
        [0] => Array
            (
                [0] => Chrome
                [1] => (direct)
                [2] => (direct)
                [3] => (not set)
                [4] => (not set)
                [5] => 1366
                [6] => 667
                [7] => 2
            )

        [1] => Array
            (
                [0] => Firefox
                [1] => (direct)
                [2] => (direct)
                [3] => (not set)
                [4] => (not set)
                [5] => 1366
                [6] => 596
                [7] => 1
            )

        [2] => Array
            (
                [0] => Internet Explorer
                [1] => (direct)
                [2] => (direct)
                [3] => (not set)
                [4] => (not set)
                [5] => 1366
                [6] => 673
                [7] => 1
            )

    )

It is returning data with respect to browser vise. I want data returned with respect to visit vise means every index of row object should be with respect to each visit so that I can make my ip information saved on my local and visit information returned by Google together in report. Is there any way to do it?

share|improve this question

migrated from stackoverflow.com Jul 21 '13 at 16:41

This question came from our site for professional and enthusiast programmers.

    
So old and not related to my problem. I think you didn't read my question –  Awais Qarni Jul 23 '13 at 15:27

2 Answers 2

Hypothetically it would be possible to set a unique identifier in your database where you are storing your IP addresses and then use the same id as a custom variable in analytics. You would set this up as follows and call this function before the _gaq.push(['_trackPageview']); function is called:

_gaq.push(['_setCustomVar', 1, 'ID', 'SET_YOUR_UNIQUE_ID_HERE', 1])

in this example I have chosen to set the variable on a user level, you could change the last value from 1 to 2 so that this is set on a session basis. I believe there may also be limitations in how many unique values can be set and I seem to think this is 50,000.

To query this data you would have to filter by the ID that you have set and therefore you would likely need to use the API to do this effectively.

I would also recommend reviewing Google Analytics TOS as it says

You will not (and will not allow any third party to) use the Service to track, collect or upload any data that personally identifies an individual (such as a name, email address or billing information), or other data which can be reasonably linked to such information by Google

In my opinion this method would not contravening Google's policy as the unique id used in GA is random and the the personally identifiable data is tied together by yourself offline. However, this is a hypothetical solution and I am not a legal professional and so if you choose to implement this it is at your own risk and i do not accept liability as it is untested.

share|improve this answer
    
I have also this thing in my mind. But my question is how can I get data with respect to this ID? Google returns data with respect to browser (group by browser), How can I get data with respect to this unique id (group by my custom unique id)? –  Awais Qarni Jul 23 '13 at 15:13
    
If you do not use the API, the easiest way would probably be to use custom reports; setting the dimension to Custom Variable (Value 01) and then having the secondary dimension and metrics set to other values you wish to evaluate. To do this you will need to select Customisation from the horizontal menu >> New Custom Report >> and then choose flat table. Depending on what you wish to evaluate this method could be quite time consuming. if you learn how to use the API you can filter each query by the custom variables value to return unique data for that user, and then cycle through each variable –  Custom Clicks Jul 23 '13 at 15:33
    
Click, My dear with due respect I think you didn't read my question carefully and didn't see the code which I have shown. I am using Google Analytics API –  Awais Qarni Jul 24 '13 at 12:33

I don't think you can get IP address from Google Analytics, it is not shown by default and using custom variables to get the information would be against their TOS. You can however get IP addresses with your own script, in PHP you would do something like $_SERVER['REMOTE_ADDR'];

Google source stating "It is not possible to track IP addresses using Google Analytics"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.