Enabling GeoLocation restrictions on Forms and Asset builders


(Harinder Singh) #1

Matrix Version: 6.47.0

I am looking into implementing a solution to enable geolocation restrictions on our online forms and asset builder assets. Is it possible to control this via triggers? Specifically, we want to either disable the page load or redirect users to a “Page Not Found” page if they are visiting from outside of whitelisted countries.

Please advise if anyone implemented such solution?


#2

Probably need to use some kind of IP to Geolocation library. Also, take a look at this if it helps!


(Harinder Singh) #3

Thanks Paul. I’ll look into it.


(Harinder Singh) #4

Updates: I ended up with the following solution so far which I have added it in my design.

%begin_frontend_asset_type_code^contains:\^page_asset_builder|page_custom_form$%
<script>
    var countryVal = "esi:vars$(HTTP_CF_IPCOUNTRY)</esi:vars>";
    if(countryVal !== "AU" && countryVal !== "NZ" ){
          window.location.href = "%globals_site_url%";
    }       
</script>
%end_frontend%

Note: Squiz team had to enable the ESI tags for me and I had to disable cache on asset containing this code.

I tried another solution using Triggers andipGeoLocation.io but it was partially working. It was doing all validation and redirection to Homepage for external users. But for the internal users, it was going into redirection loop and timing out.