Track IP Address in Google Analytics using GTM

API Connector Add-On for Google Sheets

Check out my API Connector Add-on to easily connect and pull data from thousands of platforms (e.g. Shopify, Harvest, Mailchimp, ActiveCampaign, VWO, YouTube, etc.) directly into Google Sheets.

In response to many questions about tracking IP addresses in Google Analytics, this is a follow-up post to Get Visitor IP Address with Google Tag Manager. Please follow the instructions in that post first to collect visitor IP address into a GTM Variable and create a GTM event. Once those steps are complete, you can follow these remaining steps in this post to pass the IP address to GA.

❓ It’s a grey area whether IP addresses are considered personal information. Please be aware of your site’s privacy policy, any relevant local laws, and Google’s policies regarding personally identifiable information. The new GDPR rules generally DO consider IP addresses to be personal data, as described here: https://eugdprcompliant.com/personal-data/.

STEP 1: SET UP A SESSION-SCOPED CUSTOM DIMENSION IN GA

In the Google Analytics interface, navigate to Admin > Property > Custom Definitions > Custom Dimensions

ip-address-ga-img1

Click + NEW CUSTOM DIMENSION and create a new session-scoped custom dimension called IP Address. Save it.

ip-address-ga-img2

STEP 2: RECORD THE INDEX NUMBER

After hitting Save, you’ll see your custom dimension summary screen. Note the index number that was assigned by Google Analytics. You’ll need this in a minute.

ip-address-ga-img3

STEP 3: CREATE A UNIVERSAL ANALYTICS EVENT TAG

In Google Tag Manager, click Tags > New > Universal Analytics, and choose Track Type = Event. Fill it out with the following settings:

Category = IP, Action = Sent. These names aren’t important, so you can choose different names if you prefer.
Non-Interaction Hit = True. This is to prevent the hit from affecting bounce rate.
Enable overriding settings in this tag  = checked (or, alternately, you can add the index and dimension value into your Google Analytics Settings Variable instead).
Index = index number from step 2 above
Dimension Value = {{IP Address}} . The IP Address variable should have already been implemented via the instructions in  Get Visitor IP Address with Google Tag Manager.
Trigger = ipEvent. This ipEvent trigger should also already have been implemented via the instructions in Get Visitor IP Address with Google Tag Manager.

The completed tag should look like this:

ip-address-ga-img4

CONCLUSION

The first post showed how to collect a user’s IP address into a GTM Variable. This post extends that to show how to pass that IP address into a custom dimension in Google Analytics. Because custom dimensions need to be attached to another hit like a pageview or event, the above method sends the IP address along with a dummy event. Once you complete the above directions, you will be able to access your users’ IP addresses as a Secondary Dimension in any standard report, or as a Primary Dimension in a custom report. You can also use these custom dimensions to target specific audiences for remarketing.

 

25 thoughts on “Track IP Address in Google Analytics using GTM”

    • I can’t say for sure without access to your GTM account. But when I tested my own container on your site, it worked but fired the event tag hundreds of times instead of just once. Based on that, I think you have a misconfiguration of the custom HTML tag. If you’d like me to be more specific, please give GTM access to info@ mixedanalytics.com so I can log in and check it.

      Reply
  1. I’d love to see from your perspective if I set mine up correctly… IP tracking is new to me and I tried to follow step by step – not sure what the results are supposed to look like.

    Reply
    • To check the results, you can open any report — for example, the Devices report located at Audience > Mobile > Overview. From here, open the Secondary Dimension dropdown menu and choose IP Address to see your new custom dimension. If all is working, you should see a list of IP addresses next to each device type.

      Reply
      • If you see it in GTM preview mode, then it means you’re getting the IP address back from the service (in other words, your ‘IP Detect’ tag is fine).
        Since you have IP address in GTM, it’s just like setting up any other custom dimension in GA. You need to a) attach the variable to a tag in GTM and b) set up a custom dimension in GA to receive it. Can you please clarify that your IP Address variable is named {{ipAddress}} and you’ve enabled custom dimension 1 in GA?
        Also, how are you testing this? If it’s just your own traffic, you probably won’t fire the landing page tag since you’ve already been clicking around the site, so make sure you’re testing in a new browser or incognito mode.

      • yes . Ip Address variable is ipAddress , index is 1 and i enabled in GA . I tested by checking visit of customers. Now i know i set up correctly , maybe it takes more time to appeared . Thank you Ana

  2. I don’t think you could pass any IP address data directly to GA for reporting. I think GA will automatically filter out IP-address-like data.

    Reply
  3. Thank you for making this post. I agree with the previous commenter, I don’t think you could pass any IP address data directly to GA for reporting. GA will automatically filter out IP-address-like data. It might depend on which country you are in because countries have different online privacy laws.
    Having said, I think there is a lot of value to have IP info to segment visitors by geo origin.

    Reply
    • GA doesn’t automatically filter out any data, I’ve seen this myself. They don’t even filter out much more egregious violations of personal information like names and email addresses. You could pass in credit card numbers and Google wouldn’t filter it out, as it is your own responsibility to avoid passing in personal data. I agree it does depend on which country you’re in as the laws vary on what constitutes PII.

      Reply
  4. Hi Ana, I’ve done all steps you gave but when I check the preview mode on website, just 1 tag which is “HTML tag” was fired. The “UA-event-IP” was not fired. I didn’t know why. I event tried 4 to 5 times again but It didn’t work well.
    When I checked in analytics report. It just showed the same thing at “ipAddress” column, not the IP of user.
    Can yoy help me, PL.
    I’m gonna give you the discribe image below:
    1. The preview mode: https://imgur.com/RWA2TXI
    2. Set up on GTM:
    https://imgur.com/O9Vw8PK
    https://imgur.com/xXsdX9B
    https://imgur.com/QTw9gu7
    https://imgur.com/Om5hX1K
    https://imgur.com/gZPd0Tn
    3. Set up dimension: https://imgur.com/uDVxENp
    4. Result in report: https://imgur.com/1sr7Ijo

    Reply
    • Hi there, I suspect the issue is your Referrer condition on the Theo doi IP trigger, since you’re refreshing it repeatedly while testing, so your own site is the referrer. Can you please temporarily disable that condition and see if it works?

      Reply
  5. Hi Ana,

    Again, your post solve my headache. My site has been under invalid clicks for days or longer. I tried to find the IPs to exclude them from Google Ads. Would you might kindly advise below?
    1) Does having IPs as custom dimension in GA violate Google’s regulation?
    2) I already have Client IDs as custom dimension and have those suspicious Client IDs as custom audience in GA and exclude them from Google Ads. Do you think it will work? I still see clicks from 2 of those Client IDs today.

    Thank you for the awesome posts as always.

    Reply
    • Add this.
      3) Do you have experience with invalid clicks which are done by real people. They just use their mobile devices to search and click your ads when they are BORING or feel needed. What would you do to deal this? Use 3rd party tool?

      Thank you.

      Reply
    • Thank you, Robert 🙂
      1) I linked to Google’s policies at the top of this article. They don’t have a specific regulation regarding IP addresses, though there’s a section on geolocation that you can check.
      2) I thought custom audiences are for retargeting on other websites. Can you also use them as logic to determine whether or not an ad shows on your own site? If so, then your approach could work, but if not I think you would need to use a different method to hide the ad from certain users. You should definitely be able to block based on IP addresses.
      3) Apologies, I’m not really familiar with preventing invalid ad clicks. However, I just searched for “prevent click fraud” and it looks like there are some online guides as well as software tools for managing this.

      Reply
      • Hi Ana,
        Thanks for your reply.
        2) I read it on Quora about using Client ID to block invalid clicks. Here is quote and link.
        “It is not possible via the default filters. It is however possible if you have defined a custom dimension for client ID and include the client ID in the GA hit payload. Once you have created the custom dimension the filter option gets enabled, but won’t work unless you populate your hits with the client ID.”
        https://www.quora.com/Can-I-block-a-client-ID-on-Google-Analytics-This-ID-does-not-come-from-our-internal-traffic-and-his-average-time-per-session-is-more-than-1-hour
        From my experiment, it doesn’t work the way expected. Client ID cannot be used to prevent from ads showing, unfortunately.

      • Hey Robert, as I understand it, that Quora comment is referring to blocking users from GA. I don’t think it can be used to block invalid clicks since the clicks are related to Google Ads rather than Google Analytics. Sorry this doesn’t work for you, and I hope you find a good solution.

      • May I ask a question which seems very basic. What does it mean to include the client ID in the GA hit payload? It might be the reason why ad audience exclusion by Client IDs fails. Thank you so much.

      • It means to include the client ID in a custom dimension when you send the hit to Google Analytics. But I think we’re kind of going round and round here. All these instructions apply to Google Analytics, which is a different product from Google Ads. The client ID is ONLY used for Google Analytics, so I don’t think it’s relevant for what you’re trying to do.

Leave a Comment