---
title: "Actions - Serpwise Documentation"
description: "Actions define what modifications the gateway applies when a rule's conditions match. Every SEO change is an action."
url: "https://serpwise.ai/docs/actions/"
source: "https://serpwise.ai/docs/actions/"
---
[Back to Serpwise](/)

Serpwise Documentation

Connect · Configure · Execute

Search documentation

`/`

No documentation found.

↑↓ Navigate Enter to open

Browse documentation

Actions are the “what” part of a rule. When a rule’s conditions match, the gateway executes all configured actions against the HTML response before returning it to the visitor.

A single rule can have multiple actions - for example, setting a canonical tag and injecting JSON-LD structured data in a single rule.

* * *

## Meta Tags

### `set_meta_robots`

Sets or replaces the `<meta name="robots">` tag in the page `<head>`.

**When to use:** Control crawler indexing behavior for specific pages or URL patterns.

| Parameter | Value                                                            |
|-----------|------------------------------------------------------------------|
| `content` | e.g. `noindex`, `nofollow`, `noindex, nofollow`, `index, follow` |

```
<!-- Result -->
<meta name="robots" content="noindex, nofollow">
```

**Common values:**

- `noindex` - tell all crawlers not to index this page
- `noindex, nofollow` - don’t index and don’t follow links
- `index, follow` - explicitly allow indexing (overrides a previous noindex from origin)

* * *

### `set_meta_title`

Sets or replaces the `<title>` element.

**When to use:** Override page titles without touching the CMS or codebase - useful for A/B testing titles or fixing titles across a template.

| Parameter | Value            |
|-----------|------------------|
| `content` | The title string |

* * *

### `set_meta_description`

Sets or replaces the `<meta name="description">` tag.

**When to use:** Add or fix meta descriptions on pages where the CMS doesn’t provide them.

| Parameter | Value                  |
|-----------|------------------------|
| `content` | The description string |

* * *

### `set_meta_tag`

Sets any arbitrary `<meta>` tag by name. If a tag with the same `name` attribute already exists, it’s replaced.

**When to use:** Add custom meta tags not covered by the specific actions above.

| Parameter | Value                                               |
|-----------|-----------------------------------------------------|
| `name`    | The `name` attribute (e.g. `author`, `theme-color`) |
| `content` | The `content` attribute value                       |

* * *

### `remove_meta_tag`

Removes a `<meta>` tag by its `name` attribute.

**When to use:** Strip meta tags injected by your CMS that shouldn’t appear on certain pages.

| Parameter | Value                          |
|-----------|--------------------------------|
| `name`    | The `name` attribute to remove |

* * *

## Links

### `set_canonical`

Sets or replaces the `<link rel="canonical">` tag.

**When to use:** Fix canonical tags across filtered/sorted/paginated URLs, or consolidate duplicate content.

| Parameter | Value             |
|-----------|-------------------|
| `href`    | The canonical URL |

```
<!-- Result -->
<link rel="canonical" href="https://www.example.com/products/blue-widget">
```

**Problems it solves:**

- E-commerce sites with faceted navigation (color, size filters) generating thousands of near-duplicate URLs
- CMS platforms that set incorrect canonicals on paginated pages
- Syndicated content that needs to point back to the original

* * *

### `add_hreflang`

Adds a `<link rel="alternate" hreflang="...">` tag for international SEO.

**When to use:** Implement or fix hreflang across a localized site without modifying every page template.

| Parameter | Value                                                       |
|-----------|-------------------------------------------------------------|
| `lang`    | BCP 47 language tag (e.g. `en`, `de`, `en-US`, `x-default`) |
| `href`    | The URL of the alternate page for this language             |

```
<!-- Result -->
<link rel="alternate" hreflang="en-US" href="https://www.example.com/en-us/page">
```

Create multiple `add_hreflang` actions within a single rule to build a complete hreflang set.

* * *

### `remove_hreflang`

Removes all `<link rel="alternate" hreflang="...">` tags, or a specific one by language.

**When to use:** Strip incorrect hreflang tags injected by your platform before adding corrected ones.

| Parameter | Value                                        |
|-----------|----------------------------------------------|
| `lang`    | Language tag to remove, or `*` to remove all |

* * *

## HTTP Headers

### `set_response_header`

Adds or replaces an HTTP response header.

**When to use:** Add security headers, cache-control directives, or custom headers without server config changes.

| Parameter | Value        |
|-----------|--------------|
| `name`    | Header name  |
| `value`   | Header value |

**Examples:**

```
X-Robots-Tag: noindex          ← prevents indexing via header (useful for non-HTML)
Cache-Control: max-age=3600    ← set caching behavior for CDN/browser
X-Content-Type-Options: nosniff
```

* * *

### `remove_response_header`

Removes an HTTP response header.

**When to use:** Strip headers that expose server information or conflict with your intended behavior.

| Parameter | Value                 |
|-----------|-----------------------|
| `name`    | Header name to remove |

**Examples:** Remove `X-Powered-By`, `Server`, or platform-specific headers.

* * *

## Structured Data

### `auto_schema`

Template-based Schema.org JSON-LD injection. The gateway controls `@context` and `@type` automatically - you supply only the type name and properties. If a JSON-LD block with the same `@type` already exists on the page, it is replaced rather than duplicated.

**When to use:** Add structured data across many pages without writing raw JSON-LD. Use `inject_json_ld` when you need full control over the schema object; use `auto_schema` when you want the gateway to handle the boilerplate.

| Parameter    | Value                                                                                                                         |
|--------------|-------------------------------------------------------------------------------------------------------------------------------|
| `schemaType` | Schema.org type name (e.g. `Article`, `Product`, `FAQPage`, `BreadcrumbList`)                                                 |
| `schema`     | Props object - the gateway merges these with `@context` and `@type`; any user-supplied `@context` or `@type` keys are ignored |

#### Template Variables

Any `{variable}` in a string value is resolved at request time. Variables work in nested objects and arrays.

| Variable             | Resolves to                                                                          |
|----------------------|--------------------------------------------------------------------------------------|
| `{page_title}`       | Current `<title>` text (reflects any prior `set_meta_title` action in the same rule) |
| `{page_description}` | `<meta name="description">` content                                                  |
| `{page_image}`       | `<meta property="og:image">` content                                                 |
| `{domain}`           | Domain name (e.g. `www.example.com`)                                                 |
| `{scheme}`           | Protocol (`https` or `http`)                                                         |
| `{path}`             | URL path (e.g. `/products/blue-widget`)                                              |
| `{full_url}`         | Full request URL                                                                     |
| `{query}`            | Query string (without `?`)                                                           |

You can also define **custom domain variables** that work alongside system variables. See [Domain Variables](/docs/variables) for details.

#### Structural Builders

`FAQPage` and `BreadcrumbList` accept simplified input shapes that the gateway transforms into the correct schema structure.

**FAQPage** - provide a `questions` array with `question`/`answer` pairs. The gateway expands these into the required `mainEntity` array of `Question`/`Answer` types.

```
{
  "schemaType": "FAQPage",
  "schema": {
    "questions": [
      { "question": "What is Serpwise?", "answer": "The edge proxy for the Agentic Web - purpose-built for SEO and GEO." },
      { "question": "Is it no-code?", "answer": "Yes." }
    ]
  }
}
```

**BreadcrumbList** - provide an `items` array with `name`/`url` pairs. The gateway builds `itemListElement` with auto-incrementing `position` values.

```
{
  "schemaType": "BreadcrumbList",
  "schema": {
    "items": [
      { "name": "Home", "url": "https://www.example.com/" },
      { "name": "Products", "url": "https://www.example.com/products/" },
      { "name": "Blue Widget", "url": "{full_url}" }
    ]
  }
}
```

#### Examples

**Article with template variables:**

```
{
  "schemaType": "Article",
  "schema": {
    "headline": "{page_title}",
    "description": "{page_description}",
    "image": "{page_image}",
    "url": "{full_url}",
    "publisher": {
      "@type": "Organization",
      "name": "Acme Corp",
      "url": "https://{domain}"
    }
  }
}
```

**FAQPage:**

```
{
  "schemaType": "FAQPage",
  "schema": {
    "questions": [
      { "question": "How does Serpwise work?", "answer": "It sits between your CDN and origin." }
    ]
  }
}
```

**BreadcrumbList:**

```
{
  "schemaType": "BreadcrumbList",
  "schema": {
    "items": [
      { "name": "Home", "url": "https://{domain}/" },
      { "name": "Blog", "url": "https://{domain}/blog/" }
    ]
  }
}
```

**Result:**

```
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"Article","headline":"My Article Title",...}
</script>
```

* * *

### `inject_json_ld`

Injects a JSON-LD `<script>` block into the page `<head>`.

**When to use:** Add Schema.org structured data (Product, Article, BreadcrumbList, Organization, FAQ, etc.) to pages where your CMS doesn’t support it.

| Parameter | Value                  |
|-----------|------------------------|
| `schema`  | A valid JSON-LD object |

```
{
  "@context": "https://schema.org",
  "@type": "Product",
  "name": "Blue Widget",
  "description": "A high-quality blue widget",
  "brand": {
    "@type": "Brand",
    "name": "Acme Corp"
  }
}
```

Multiple `inject_json_ld` actions can be used in the same rule - each generates a separate `<script type="application/ld+json">` block.

* * *

### `modify_json_ld`

Modifies an existing JSON-LD block already present in the page. Targets a specific `@type` and merges or overwrites specific properties.

**When to use:** Augment JSON-LD that your CMS already outputs - add missing properties without replacing the entire schema block.

| Parameter    | Value                                             |
|--------------|---------------------------------------------------|
| `type`       | The `@type` to target (e.g. `Product`, `Article`) |
| `properties` | Key-value pairs to merge into the matched schema  |

* * *

## HTML Injection

### `inject_html`

Injects an arbitrary HTML snippet at a specific position in the document.

**When to use:** Add scripts, tracking pixels, banners, or any custom HTML without a code deployment.

| Parameter  | Value                                                               |
|------------|---------------------------------------------------------------------|
| `position` | Where to inject: `head_start`, `head_end`, `body_start`, `body_end` |
| `html`     | The HTML string to inject                                           |

| Position     | Where it goes                |
|--------------|------------------------------|
| `head_start` | Immediately after `<head>`   |
| `head_end`   | Immediately before `</head>` |
| `body_start` | Immediately after `<body>`   |
| `body_end`   | Immediately before `</body>` |

**Example - inject a tracking pixel before `</body>`:**

```
<img src="https://analytics.example.com/pixel.gif" width="1" height="1" alt="">
```

* * *

### `remove_element`

Removes all HTML elements matching a CSS selector from the document.

**When to use:** Strip elements injected by your CMS or theme that shouldn’t appear on certain pages - for example, removing social share buttons from noindex pages, or stripping duplicate schema blocks.

| Parameter  | Value                |
|------------|----------------------|
| `selector` | A valid CSS selector |

**Examples:**

```
.social-share-buttons    ← remove by class
#cookie-banner           ← remove by ID
script[src*="analytics"] ← remove analytics scripts on specific pages
meta[name="generator"]   ← remove CMS fingerprinting meta tags
```

* * *

## Find & Replace

### `find_and_replace`

Performs text substitution across the entire HTML response body.

**When to use:** Fix repeated text patterns across pages - update old brand names, fix broken URLs in content, replace deprecated phrases, or rewrite specific strings that your CMS outputs incorrectly.

**Problems it solves:**

- A brand rename where old name appears across thousands of pages
- An incorrect URL pattern embedded in CMS templates
- Deprecated rel attributes or aria labels in template markup

| Parameter       | Value                                                                 |
|-----------------|-----------------------------------------------------------------------|
| `search`        | The text or regex pattern to find                                     |
| `replace`       | The replacement string                                                |
| `isRegex`       | `true` to treat `search` as a regex pattern; `false` for literal text |
| `caseSensitive` | `true` or `false` (default: `true`)                                   |

**Literal text example:**

```
Find:    Acme Widget Co.
Replace: Acme Corporation
```

**Regex example with capture group:**

```
Find:    href="http://old-domain\.com(/[^"]*)"
Replace: href="https://www.new-domain.com$1"
Regex:   true
```

* * *

## Conversion Tracking

### `fire_conversion_event`

Fires a server-side conversion event to connected tracking platforms (Meta CAPI, TikTok Events API, Google Ads Enhanced Conversions).

**When to use:** Track purchases, leads, add-to-cart, and other conversion events server-side - bypassing ad blockers and Safari ITP.

| Parameter    | Value                                                                                                                                                                        |
|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `event_type` | `purchase`, `add_to_cart`, `lead`, `page_view`, `initiate_checkout`, `add_payment_info`, `search`, `view_content`, `complete_registration`, `contact`, `subscribe`, `custom` |
| `extraction` | Configuration for extracting event data (value, currency, order ID) from the HTML response                                                                                   |

Events are sent to all active integrations configured for the domain. A first-party cookie is set on the visitor to enable cross-session attribution.

* * *

## Robots.txt

### `modify_robots_txt`

Modifies the robots.txt response served by your domain.

**When to use:** Add, update, or replace robots.txt directives without server access - useful when your CMS generates an incorrect robots.txt.

| Parameter | Value                                                                                                           |
|-----------|-----------------------------------------------------------------------------------------------------------------|
| `mode`    | `append` - adds to existing content; `replace` - replaces entirely; `generate` - creates from scratch if absent |
| `content` | The robots.txt content to apply                                                                                 |