So I have an AMP form that, depending on where the user is, needs to redirect them to different places. I have a set-up that uses two hidden fields likes so:
<input name="ip_address" type="hidden" value="<?php echo getRemoteIPAddress()?>">
<input name="lead_geo" type="hidden" value="<?php echo getGeoByIp()?>">
Along with corresponding functions that I know work correctly as they've been tried and tested throughout the rest of the site.
Then I have my endpoint set up with a qualifier like so:
if($lead_geo == '' || $lead_geo == 'CA' || $lead_geo == 'AZ' || $lead_geo == 'IL' || $lead_geo == 'TX' || strlen($lead_geo) > 5) {
header("AMP-Redirect-To: ".$location-specific-destination);
} else {
header("AMP-Redirect-To: ".$default);
}
And this all works perfectly locally, on stage, and on production until the amp page is cached. The problem is Google caches the first IP that requests it. Is there a way of getting a users location on the cached side? Or even if I could just get their IP on the page I could have the endpoint get the location from it.
TLDR: How can I get a user's location or even just IP address when they submit an AMP form.