Integrating with Custom Log Drain
This guide walks you through the process of implementing AI Bot Analytics using a custom integration. This method allows you to integrate with any platform or custom application by making direct HTTP requests to Writesonic's analytics endpoint.
Prerequisites
- An active Writesonic account
- Development access to your website or application
- Ability to make HTTP POST requests from your server
- Access to request headers and metadata
Phase 1: Start in Writesonic
- Head over to the AI Bot Analytics page on Writesonic and choose ‘Custom’ as a provider
- Click on ‘Continue’ to initialize the integration.
- Writesonic will generate a unique API key for your website.
Phase 2: Get Integration Details
Step 1: Copy the Endpoint URL
Copy the following endpoint URL that you'll use for sending analytics data:
https://ingestion.writesonic.com/api/v1/analytics/ingest
Step 2: Note the Authentication Headers
You'll need to include the following header in all your requests:
- Header Key:
x-api-key - Header Value: Copy the API key provided by Writesonic (unique to your project)
Phase 3: Implement the Integration
Request Format
Make a POST request to the endpoint URL with the following JSON body fields:
| Field | Type | Description | Example |
|---|---|---|---|
ip | string | The client's IP address | 192.168.1.100 |
x_real_ip | string | X-Real-IP header | 203.0.113.1 |
ua | string | User-Agent header from the request | Mozilla/5.0 (compatible; Googlebot/2.1) |
country_code | string | ISO country code | US, GB, IN |
referrer | string | Referrer header value | https://chatgpt.com/ |
url | string | The requested URL path | https://writesonic.com/about-us |
method | string | HTTP method used | POST |
x_forwarded_for | string | X-Forwarded-For header chain | 203.0.113.1, 198.51.100.1 |
response_status | string | HTTP response status code | 200, 404, 500 |
Curl example
curl -X POST 'https://ingestion.writesonic.com/api/v1/analytics/ingest' \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY_HERE" \
-d '{
"ip": "192.168.1.1",
"x_real_ip": "203.0.113.1",
"ua": "Mozilla/5.0 (compatible; Googlebot/2.1)",
"referrer" : "https://chatgpt.com/",
"country_code": "US",
"url": "https://writesonic.com/about-us",
"method": "GET",
"response_status": "200",
"x_forwarded_for" : "203.0.113.1,198.51.100.1"
}'
Phase 4: Testing and Verification
Test Your Integration
- Implement the code in your application
- Make a few test requests to your website
- Check that the requests are being sent to the Writesonic endpoint
- Monitor your application logs for any errors
Verify Installation in Writesonic
- Go to AI Bot Analytics Page in Writesonic.
- Click on "Verify Integration" to confirm that your Custom integration is working properly
- Once verified, you'll be redirected to your analytics dashboard. The process typically finishes in 1–2 minutes but may take up to 5 minutes.
Best Practices
Performance Considerations
- Asynchronous Processing: Send analytics data asynchronously to avoid impacting response times
- Error Handling: Implement proper error handling to prevent analytics failures from affecting your main application
- Rate Limiting: Implement client-side rate limiting to avoid overwhelming the endpoint
Data Quality
- IP Address: Use the most accurate IP address available (consider proxies and load balancers)
- User Agent: Always include the complete User-Agent string
- URL Normalization: Ensure URLs are properly formatted and complete
Security
- API Key Protection: Keep your API key secure and never expose it in client-side code
- HTTPS Only: Always use HTTPS for requests to the Writesonic endpoint
- Data Sanitization: Sanitize user data before sending to prevent injection attacks
Troubleshooting
Common Issues
- 401 Unauthorized: Check that your API key is correct and properly included in headers
- 422 Unprocessable Entity: Verify that your JSON payload matches the required format
- Network Errors: Ensure your server can make outbound HTTPS requests
- Missing Data: Check that you're capturing all available request headers and metadata
Debugging Tips
- Log Requests: Log the data you're sending for debugging purposes
- Test with curl: Use curl to test the endpoint manually
- Check Response: Always check the HTTP response code and body for error details
Updated about 3 hours ago
