I have a problem.
I have a piece of code, that I send to websites to be placed inside the <head></head>
right at the very beginning of the header. My code will run and collect some data and pass the result to the rest of the page (ad servers, forms, etc., for example).
My problem is that I need to limit the number of times this code can make calls back to my server and that needs to be based on user location (city, more specifically). I cannot use the ad server, and benefit from its targeting capabilities because I do need to run this code before everything else.
I was thinking if there was any sort of script that would allow me to identify the user location and make the decision to whether or not to call my server, therefore making sure that I am only using my resources when it is actually needed.
I thought about using the html5 geolocation API but it requires user interaction. Then I was thinking about using a service like IpRegistry.co, to:
- query for the location and if ;
- location=desired location;
- then load javascript code;
- otherwise do nothing;
I am not sure if this is possible and how to do it. Any help would be greatly appreciated and desired. I am ready to explore opportunities here.
If I didn't stress enough, it needs to happen inside the header, not on the body.
Thanks in advance.
PC