Re: Javascript for country code or auto detect country's IP address.

asclepius22
Level 1

Javascript for country code or auto detect country's IP address.

Hello everyone, 

 

I am wondering if anyone knows if it's possible to code javascript into marketo form so that it can either 

 

1) Automatically detect the visitor's country based on their IP address?
2) Allow visitor to select country code from the field (dropdown)

 

I am not a programmer and have almost no knowledge in coding. If anyone knows how, that will be a great help! 

Thank you in advance. 

-Peter

2 REPLIES 2
Darshil_Shah1
Level 10 - Community Advisor

Re: Javascript for country code or auto detect country's IP address.

An external JS can detect Country based on the IP address (Geo-IP), this value can be used to auto-populate Country in the form (not a fan of auto-populating country based on the browser inferred values as you may risk capturing the wrong country value in-case a person is using a VPN to impersonate being in a different geographical region/country or confuse where the lead is today with where they actually live/work.)

 

Marketo's munchkin also detects the Inferred Country value based on the Geo-IP, the Inferred Country is set for the known person and is also detected for the anonymous visitors which can be viewed in the webpage activity report. Alternatively you can also use Marketo's RTP JS to get the visitor's location data.

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Javascript for country code or auto detect country's IP address.

There are 3 different ways to augment the Inferred Country field:

  1. A Select where the person personally testifies to their location. This is by far preferred, especially in tightly regulated industries where you can’t merely guess based on their current public IP.
  2. A remote paid service such as MaxMind that can get granular data about the IP, but still fails if someone is behind a VPN, on vacation, etc.
  3. The browser’s built-in Geolocation popup (“example.com wants to know your location”) which, if the end user opts in, can provide accurate data about the person’s current location but again will not compensate for the person being in transit.

You can interweave all of these using JS, i.e. try to get them to opt in to #3 and then fallback to #1. There’s some working Geolocation code in this old demo.