BrowsersConverter.php
1 year ago
DataConverterInterface.php
4 years ago
FilterConverter.php
2 years ago
NumberConverter.php
1 year ago
PagesTitleConverter.php
1 year ago
PagesUrlConverter.php
1 year ago
PlatformConverter.php
4 years ago
ReferrersConverter.php
4 years ago
SearchEngineConverter.php
1 year ago
SearchQueryConverter.php
1 year ago
SubtableConverter.php
1 year ago
UserCityConverter.php
4 years ago
UserCountryConverter.php
4 years ago
UserRegionConverter.php
4 years ago
VisitorsConverter.php
1 year ago
VisitsTimeConverter.php
7 months ago
SearchQueryConverter.php
30 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WpMatomo\WpStatistics\DataConverters; |
| 4 | |
| 5 | use Piwik\DataTable; |
| 6 | |
| 7 | /** |
| 8 | * aggregate data on the number fields |
| 9 | * |
| 10 | * @package WpMatomo |
| 11 | * @subpackage WpStatisticsImport |
| 12 | */ |
| 13 | class SearchQueryConverter extends FilterConverter implements DataConverterInterface { |
| 14 | |
| 15 | public static function convert( array $wp_statistics_data ) { |
| 16 | $first_page = reset( $wp_statistics_data ); |
| 17 | $key = isset( $first_page['uri'] ) ? 'uri' : 'str_url'; |
| 18 | |
| 19 | $data = self::filter( $wp_statistics_data, '?s=', $key ); |
| 20 | foreach ( $data as $id => $url ) { |
| 21 | $matches = []; |
| 22 | if ( preg_match( '/\?s=(.+)$/', $url[ $key ], $matches ) ) { |
| 23 | $data[ $id ]['keyword'] = $matches[1]; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | return self::aggregate_by_key( $data, 'keyword' ); |
| 28 | } |
| 29 | } |
| 30 |