0

I am using a Maps API which costs quite a lot per request

  • My goal is to make as little requests as possible, so i use a lot caching here
  • The API is called on each pageload but doesn't need to be called for non-human user like googlebot

So, what's the best way to detect if the user is a bot or human?

  • Please no captcha tricks here.
  • Maybe we can check on mouse events on pageload and show the user a loading icon while checking (and technical idea how to realize this)?
  • Better ideas?
skaffman
  • 398,947
  • 96
  • 818
  • 769
Lupo
  • 2,884
  • 5
  • 24
  • 30
  • If you can live with some users without javascript can't access the map, put the map code in javascript. Bots don't execute javascript. – Yogu Dec 21 '11 at 22:51
  • See http://stackoverflow.com/questions/677419/how-to-detect-search-engine-bots-with-php for inspiration :) – Stefan Dec 21 '11 at 22:54

2 Answers2

1

I would use Javascript to load the map image. Web scrapers and robots typically do not attempt to parse or execute Javascript. This ensures that your API call is only made when a browser visits the page.

You could achieve this by breaking out your API call into a separate page that you call via AJAX.

Interrobang
  • 16,984
  • 3
  • 55
  • 63
  • Server-side headless browser implementations + OCR renders the old JavaScript-only approach useless as real browser visits can be emulated and screenshots taken. An example of this is Puppeteer: https://github.com/GoogleChrome/puppeteer –  Jun 21 '18 at 09:26
1

use a javascript function e.g. initialize() to setup your Google maps API call.

e.g.

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=set_to_true_or_false"></script>
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  }

</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>

(copied from the api v3 reference)

maxRoald
  • 99
  • 1
  • 4
  • thank you, unfortunately especially the googlebot costs a lot and queries the API a lot ;) → guess it eats JS... – Lupo Dec 24 '11 at 11:01
  • if still in need for a solution and you know your bots e.g. google follows these measures ([link](http://support.google.com/webmasters/bin/answer.py?hl=de&answer=1061943)) check out the meta tag at the end of the page, happy savings on Xmas eve ;) – maxRoald Dec 24 '11 at 21:22