Coding agents

Production sites

Staging is best: bot protection is usually off and analytics are separate. On production, set three things up first, or virtual users may be blocked as an attack or counted as real traffic.

How virtual users identify themselves

WhatValueUse it to
Header X-Usercase-Agentthe kind of visitor, e.g. qa-exploreseparate them in logs and server-side analytics
Header X-Usercase-Keyyour own secret, sent only to your sitelet them through your firewall or CDN
User-Agent suffixUsercaseQA/1.0 (<kind>)exclude them in browser analytics and in logs that drop headers

Let them through your firewall

Make a random secret of 16 characters or more, pass it as USERCASE_AGENT_KEY, and allow requests whose X-Usercase-Key header matches it. Don’t allow on X-Usercase-Agent alone; anyone can send that.

node -e "console.log(require('crypto').randomBytes(24).toString('base64url'))"

Keep them out of analytics and logs

  • In analytics, filter out sessions whose user agent contains UsercaseQA.
  • In logs, separate them by the X-Usercase-Agent header or the user-agent suffix.