Documentation Guides How to Add a Custom Search Engine in WP Statistics with Filter

How to Add a Custom Search Engine in WP Statistics with Filter

How to Add a Custom Search Engine in WP Statistics with Filter

WP Statistics is a popular WordPress plugin that provides detailed insights into your website’s traffic. It can track visitors, page views, search terms, and more. One of its features is the ability to track which search engines your visitors are using to find your website.

By default, WP Statistics tracks the following search engines:

  • Google
  • Yahoo
  • Bing
  • Ask
  • DuckDuckGo

However, you can also add custom search engines to WP Statistics. This is useful if you want to track traffic from other search engines, such as Naver or Daum.

To add a custom search engine to WP Statistics, you can use the following filter:

PHP

add_filter('wp_statistics_search_engine_list', function ($engines) {

    $engines['naver'] = [
        'name' => 'Naver',
        'translated' => __('Naver', 'wp_statistics'),
        'tag' => 'naver',
        'sqlpattern' => '%naver.com%',
        'regexpattern' => 'naver.com',
        'querykey' => 'query',
        'image' => 'naver.png',
        'logo_url' => 'naver.png'
    ];

    $engines['daum'] = [
        'name' => 'Daum',
        'translated' => __('Daum', 'wp_statistics'),
        'tag' => 'daum',
        'sqlpattern' => '%daum.net%',
        'regexpattern' => 'daum\.net',
        'querykey' => 'q',
        'image' => 'daum.png',
        'logo_url' => 'daum.png'
    ];

    return $engines;
});

This filter will add two new search engines to WP Statistics: Naver and Daum. You can customize the filter to add additional search engines, as well as modify the search engine information (e.g., name, tag, logo).

Related Document: Basic Tracking Settings