Custom Search Parameter Integration: Beyond WordPress Default Search
WordPress traditionally uses the ‘?s=’ parameter for search queries, but modern web applications often require different search parameters. Search Insights allows you to track searches using custom parameters, making it compatible with headless WordPress setups, REST APIs, and custom search implementations. In this guide, we’ll explore how to configure and use custom search parameters effectively while maintaining accurate analytics.
Understanding Custom Search Parameters
Think of search parameters as the language your search system uses to communicate with WordPress. While WordPress natively speaks using ‘?s=’, your application might need to use a different dialect. For instance, the WordPress REST API uses ‘?search=’, while WooCommerce might use ‘?product_search=’ for product searches. Search Insights acts as a translator, ensuring all these different search languages are properly understood and tracked.
Configuring Custom Search Parameters
To set up a custom search parameter in Search Insights:
- Navigate to Search Insights settings
- Locate the “Custom Search Parameter” field
- Enter your desired parameter (without the question mark)
- Save your changes
For example, if your search URLs look like ‘example.com/?find=search-term’, you would enter ‘find’ as your custom parameter.
Common Integration Scenarios
WordPress REST API Integration
The WordPress REST API uses ‘?search=’ as its search parameter. To track these searches:
{
// Example REST API search URL
// /wp-json/wp/v2/posts?search=example
// Set custom parameter to: search
}
WooCommerce Product Search
WooCommerce product searches might use specialized parameters. Configure these by:
{
// Example WooCommerce search URL
// /shop/?product_search=example
// Set custom parameter to: product_search
}
Validating Your Configuration
After setting up a custom search parameter, it’s crucial to verify that searches are being tracked correctly. Here’s how to validate your configuration:
- Perform test searches using your custom parameter
- Check the Search Insights dashboard for new entries
- Verify that search result counts are accurate
- Confirm that search origins are properly recorded
Troubleshooting Common Issues
Searches Not Being Tracked
If searches aren’t appearing in your analytics:
- Verify your parameter exactly matches your URL structure
- Check if searches meet minimum/maximum length requirements
- Ensure the search isn’t being filtered by your exclusion rules
Incorrect Result Counts
If result counts seem incorrect, verify:
- Custom post types are properly included in search results
- Search query modifications aren’t affecting result counts
- Cache plugins aren’t interfering with result counting
Best Practices
Follow these guidelines for optimal custom search parameter implementation:
- Use simple, descriptive parameter names
- Maintain consistency across your application
- Document your custom parameter for future reference
- Regularly validate tracking accuracy
Advanced Configurations
For complex setups, you might need to track multiple search parameters. While Search Insights officially supports one custom parameter, you can achieve this through custom code:
/**
* Example code for tracking multiple parameters
* Add to your theme's functions.php
*/
add_filter('wpsi_get_caller_by_search_parameter', function($caller, $parameter) {
switch($parameter) {
case 'product_search':
return 'woocommerce';
case 'find':
return 'custom_search';
default:
return $caller;
}
}, 10, 2);
Conclusion
Custom search parameter integration allows Search Insights to adapt to your specific needs while maintaining comprehensive search analytics. By properly configuring and validating your setup, you can ensure accurate tracking regardless of your search implementation. Remember to regularly review your search analytics to confirm everything continues working as expected after making any changes to your search system.