title: Limit the number of times my code is loaded on a web page based on geo targeting - javascript
body: <p>I have a problem.</p>
  <p>I have a piece of code, that I send to websites to be placed inside the <code>&lt;head&gt;&lt;/head&gt;</code> 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).</p>
  <p>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.</p>
  <p>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.</p>
  <p>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:</p>
  <ul>
  <li>query for the location and if ;</li>
  <li>location=desired location;</li>
  <li>then load javascript code;</li>
  <li>otherwise do nothing;</li>
  </ul>
  <p>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.</p>
  <p>If I didn't stress enough, it needs to happen inside the header, not on the body.</p>
  <p>Thanks in advance.</p>
  <p>PC</p>