> ## Documentation Index
> Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# User Agent Filtering Example

> Learn how to filter traffic based on user agent strings using Traffic Policy to deliver tailored content or block specific bots.

With Traffic Policy, ngrok automatically parses out useful information from the request's `User-Agent` header and makes them [available as variables](/traffic-policy/variables/req/#requser-agentname). You can use them to deliver tailored content to users based on their browser and device, or to customize or block for SEO crawlers and bots.

This rule delivers tailored content to Microsoft Edge users by matching on the `req.user_agent.name` value.

<CodeGroup>
  ```yaml policy.yml theme={null}
  on_http_request:
  - expressions:
    - req.user_agent.name == 'Edge'
    actions:
    - type: custom-response
      config:
        status_code: 200
        body: Hello Edge User!
  ```

  ```json policy.json theme={null}
  {
    "on_http_request": [
      {
        "expressions": [
          "req.user_agent.name == 'Edge'"
        ],
        "actions": [
          {
            "type": "custom-response",
            "config": {
              "status_code": 200,
              "body": "Hello Edge User!"
            }
          }
        ]
      }
    ]
  }
  ```
</CodeGroup>

You can also quickly block bots from your site by denying them by user-agent using the handy boolean flag.

<CodeGroup>
  ```yaml policy.yml theme={null}
  on_http_request:
  - expressions:
    - req.user_agent.is_bot
    actions:
    - type: deny
      config:
        status_code: 403
  ```

  ```json policy.json theme={null}
  {
    "on_http_request": [
      {
        "expressions": [
          "req.user_agent.is_bot"
        ],
        "actions": [
          {
            "type": "deny",
            "config": {
              "status_code": 403
            }
          }
        ]
      }
    ]
  }
  ```
</CodeGroup>

Check out the [ngrok variable documentation](/traffic-policy/variables/req/#requser-agentname) for all the values you can use in your policy.
