pawel
pawel

Reputation: 508

Does Google Universal Analytics support x-forwarded-for header for ip filters?

Does Google Universal Analytics support x-forwarded-for header for ip filters?

I am trying to filter out internal ips but it doesn't seem to work. The application is sitting behind a proxy, so the client's ip is in the x-forwarded header.

Upvotes: 2

Views: 2522

Answers (2)

Lekoaf
Lekoaf

Reputation: 1049

I haven't actually tested this solution yet, but I'm working on it.

It seems like you should be able to do something like this:

import ua from 'universal-analytics'
import publicIp from 'public-ip'

const user = ua(GOOGLE_ANALYTICS_ID)

const uip = await publicIp.v4()
user.set('uip', uip)

After that, you have set the users IP for all coming events and page views.

Upvotes: 0

Eike Pierstorff
Eike Pierstorff

Reputation: 32770

According to this question the measurement protocol (which forms the base for all versions of the Google Analytics tracking) ignores x-forwarded ip headers.

This is solved in serverside implementations as Google has added a parameter uip (must be a valid IP, will always be anonymized by setting the last three numbers to 000) to the measurement protocol to send a clients ip. I don't know terribly much about proxy servers, but it might be possible to stitch the parameter into the request instead of using a header field.

Upvotes: 2

Related Questions