Personalize links based on IP Address?


#1

I have an image link in my footer that I would like to direct to different webpages based on the visitor’s IP address. If someone is located in the Chicagoland area, I would like them to go to one website, if they are located in New York City, I would like them to go someplace else, etc. I would ideally like to do this at the city level because in CA, I have different sites for LA, San Diego, and San Francisco, but if it can only be done at the state level, I can start there.

I know I can make the content “smart” and set up rules based on state/region IP addresses of visitors who are in my contacts, but I would like to make rules for everyone who visits my website, not just those who are in my contacts.

When I contacted Hubspot, they said I could accomplish this by adding a Custom HubL module to my template and creating IF statements via hubL rules. They recommended that I post to this forum to get help on how to do that.


#2

@Boosterize I’m not HubL would be the best option as that will get executed upon building of the site and not after it is built and a prospect is viewing it. That level of granularity isn’t built into HubSpot. You will have to write the reverse IP lookup your self. I would fire that code in JavaScript on page load. You could grab the IP address and then do the reverse IP lookup. Then when you have the result back from the lookup then I would create a switch block(as it would be easier to read/maintain then a giant if/else block) to decide what link to show to your project.

The challenge it will be for this is once you have the IP address where are you going to make the reverse IP lookup too.

After doing some digging. You can use HubL as well to grab the remote Ip address initially.

here is how.

{{ request.remote_ip }}