> For the complete documentation index, see [llms.txt](https://plugin-pulse.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://plugin-pulse.gitbook.io/docs/server-actions.md).

# Server Actions

How to track server actions with PluginPulse

Tracking server actions with PluginPulse is as easy as tracking them on the client. The main difference is how you load the PluginPulse tracking code into your plugin.

### Importing PluginPulse for server actions

Instead of a script snippet in the header, PluginPulse is loaded into a server action via an [npm package](https://www.npmjs.com/package/@jakebennett18505/pluginpulse) in the package.json section in your server action (found at the bottom of the page).

{% stepper %}
{% step %}

### Add npm package

{% code title="package.json" %}

```json
{
    "dependencies": {
        "pluginpulse": "latest"
    }
}
```

{% endcode %}
{% endstep %}

{% step %}

### Rebuild the package.json

<figure><img src="https://2901193222-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ1yHF1hKI8JjD5fgQVKF%2Fuploads%2F4s4A5xqu9UqIB1XfnC7g%2FScreenshot%202025-07-03%20at%2014.42.54.png?alt=media&amp;token=4a085b26-b3b9-41a4-ad13-009b875873c2" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Import into action

Note: The server action is synchronous by default. To use PluginPulse, convert your function to async.

```javascript
async function(properties, context) {
    const { pluginpulse } = require("pluginpulse");
}
```

{% endstep %}
{% endstepper %}

### Sending events in server actions

The overall structure of the event remains very similar. The only change is in order to identify the application, you need to pass the context from the parent function along with your plugin id and payload.

### Parameters

<table><thead><tr><th width="124.58984375">Parameter</th><th width="100.01953125">Required</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td>plugin_id</td><td>Yes</td><td>Your PluginPulse plugin ID</td><td>"1706526741286x876166435619471400"</td></tr><tr><td>context</td><td>Yes</td><td>The context of the action that includes the app identifier</td><td>-</td></tr><tr><td>event_name</td><td>No</td><td>Name of the event/feature (default: "Server Action")</td><td>"Export PDF"</td></tr><tr><td>payload</td><td>No</td><td>Custom JSON data for additional context</td><td><code>{format: "pdf", pages: 5}</code></td></tr></tbody></table>

#### Basic

When passing no information, the below code will result in a PluginPulse event with the name "Server Action"

```javascript
async function(properties, context) {
    const { pluginpulse } = require("pluginpulse");

    // Your existing code...

    await pluginpulse("your-plugin-id", context);
}
```

#### Custom data

As with client side actions, you can define the data you want to pass.

```javascript
async function(properties, context) {
  const { pluginpulse } = require("pluginpulse");
  
  // Your existing code...
  
  await pluginpulse("your-plugin-id", context, {
    event_name: "PDF Generated",
    payload: {
      size: "A4",
    },
  });
}

```

{% hint style="warning" %}
**The plugin version isn't available in the server action context, so all server events will be sent with the version as `backend`**
{% endhint %}
