Installation

Install the Strapi integration package:
npm install @apitraffic/strapi
Node 18+ required

Setup

1. Install the Plugin

Add the ApiTraffic plugin to your Strapi application:
npm install @apitraffic/strapi --save

2. Add to Middlewares Configuration

The middleware must be added to the config/middlewares.js file:
module.exports = [
  'strapi::logger',
  'strapi::errors',
  'strapi::security',
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
  // Add ApiTraffic middleware
  'plugin::apitraffic.apitraffic',
];

3. Environment Configuration

Add the required environment variables to your .env file:
.env
API_TRAFFIC_TOKEN=your-api-token
API_TRAFFIC_BUCKET=your-bucket-id

Configuration

Required Environment Variables

Environment VariableRequiredTypeDescription
API_TRAFFIC_TOKENYesStringIngest token from your ApiTraffic account
API_TRAFFIC_BUCKETYesStringBucket ID for data organization

Optional Configuration

You can also configure additional options by creating a plugin configuration file at config/plugins.js:
module.exports = {
  'apitraffic': {
    enabled: true,
    config: {
      token: process.env.API_TRAFFIC_TOKEN,
      bucket: process.env.API_TRAFFIC_BUCKET,
      interceptOutbound: true,
      debug: false
    }
  }
};

Features

Automatic API Monitoring

Once installed, ApiTraffic automatically monitors:
  • Content API requests - All requests to your Strapi content endpoints
  • Admin API requests - Administrative operations and user management
  • Custom API routes - Any custom routes you’ve added to your Strapi application
  • Plugin API calls - Requests to installed plugin endpoints

Workflow Integration

ApiTraffic’s workflow engine allows you to create automated workflows that trigger based on your Strapi API activity:
  • Content Creation Workflows - Trigger actions when new content is created
  • User Registration Flows - Automate user onboarding processes
  • Data Synchronization - Sync content changes with external systems
  • Notification Systems - Send alerts based on API usage patterns

Real-time Analytics

Monitor your Strapi application with comprehensive analytics:
  • Request volume and patterns
  • Response times and performance metrics
  • Error rates and debugging information
  • User activity and content usage statistics

Security Features

Data Redaction

ApiTraffic automatically redacts sensitive data based on your account settings. Configure redaction rules in your ApiTraffic dashboard to protect:
  • User passwords and authentication tokens
  • Personal identifiable information (PII)
  • Payment and financial data
  • Custom sensitive fields

Request Exclusions

Exclude specific endpoints from monitoring by configuring exclusion rules in your ApiTraffic account. Common exclusions for Strapi include:
  • Health check endpoints (/_health)
  • Static asset requests
  • Admin panel assets
  • Internal monitoring endpoints

Advanced Usage

Custom Tagging

While Strapi doesn’t support direct tagging in middleware, you can add custom tags through controller extensions:
// In your custom controller
module.exports = {
  async find(ctx) {
    // Add custom context through Strapi's built-in logging
    strapi.log.info('Custom operation', {
      userId: ctx.state.user?.id,
      contentType: 'articles'
    });
    
    return await super.find(ctx);
  }
};

Webhook Integration

Combine ApiTraffic with Strapi webhooks for comprehensive monitoring:
// config/plugins.js
module.exports = {
  'apitraffic': {
    enabled: true,
    config: {
      token: process.env.API_TRAFFIC_TOKEN,
      bucket: process.env.API_TRAFFIC_BUCKET
    }
  },
  'webhooks': {
    enabled: true,
    config: {
      // Configure webhooks to work alongside ApiTraffic
    }
  }
};

Troubleshooting

Ensure the ApiTraffic middleware is properly added to your config/middlewares.js file and placed in the correct order.
Verify that API_TRAFFIC_TOKEN and API_TRAFFIC_BUCKET are set in your .env file and that Strapi is loading them correctly.
Check that the plugin is properly installed and that your package.json includes @apitraffic/strapi in dependencies.
If you’re experiencing performance issues, consider adjusting the sampling rate in your ApiTraffic account settings.

Debug Mode

Enable debug logging by setting the debug flag in your plugin configuration:
// config/plugins.js
module.exports = {
  'apitraffic': {
    enabled: true,
    config: {
      token: process.env.API_TRAFFIC_TOKEN,
      bucket: process.env.API_TRAFFIC_BUCKET,
      debug: true
    }
  }
};

Strapi Marketplace

The ApiTraffic plugin is available on the Strapi Marketplace for easy discovery and installation.

Use Cases

Content Management Monitoring

  • Track content creation, updates, and deletions
  • Monitor user engagement with different content types
  • Analyze API usage patterns for optimization

Performance Optimization

  • Identify slow-performing endpoints
  • Monitor database query performance
  • Track memory and CPU usage patterns

Security Monitoring

  • Detect unusual API access patterns
  • Monitor authentication failures
  • Track admin panel usage

Integration Workflows

  • Automatically sync content with external systems
  • Trigger email campaigns based on content changes
  • Update search indexes when content is modified

Next Steps