Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
ISAICP-5342: Integrate with the search analytics data of webtools.
Browse files Browse the repository at this point in the history
  • Loading branch information
idimopoulos authored and claudiu-cristea committed Dec 3, 2019
1 parent 2d1d0f1 commit 1c2e21e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
isa2_analytics.oe_webtools_analytics_subscriber:
class: Drupal\isa2_analytics\EventSubscriber\WebtoolsAnalyticsSubscriber
arguments: ['@entity_type.manager', '@og.context']
arguments: ['@entity_type.manager', '@request_stack', '@current_route_match', '@og.context']
tags:
- { name: event_subscriber }
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Drupal\isa2_analytics\EventSubscriber;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\CurrentRouteMatch;
use Drupal\oe_webtools_analytics\AnalyticsEventInterface;
use Drupal\og\OgContextInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\oe_webtools_analytics\Event\AnalyticsEvent;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Subscriber that acts on visitor analytics being collected for reporting.
Expand All @@ -22,6 +24,20 @@ class WebtoolsAnalyticsSubscriber implements EventSubscriberInterface {
*/
protected $entityTypeManager;

/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $currentRequest;

/**
* The current route match.
*
* @var \Drupal\Core\Routing\CurrentRouteMatch
*/
protected $routeMatch;

/**
* The OG context service.
*
Expand All @@ -34,11 +50,17 @@ class WebtoolsAnalyticsSubscriber implements EventSubscriberInterface {
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The http request stack.
* @param \Drupal\Core\Routing\CurrentRouteMatch $routeMatch
* The current route match.
* @param \Drupal\og\OgContextInterface $ogContext
* The OG context service.
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager, OgContextInterface $ogContext) {
public function __construct(EntityTypeManagerInterface $entityTypeManager, RequestStack $requestStack, CurrentRouteMatch $routeMatch, OgContextInterface $ogContext) {
$this->entityTypeManager = $entityTypeManager;
$this->currentRequest = $requestStack->getCurrentRequest();
$this->routeMatch = $routeMatch;
$this->ogContext = $ogContext;
}

Expand Down Expand Up @@ -86,11 +108,29 @@ public function setSiteSection(AnalyticsEventInterface $event) {
}
}

/**
* Sets the webtools search data in the MATOMO json.
*
* @param \Drupal\oe_webtools_analytics\AnalyticsEventInterface $event
* Response event.
*/
public function setSearchData(AnalyticsEventInterface $event) {
if ($this->routeMatch->getRouteName() !== 'view.search.page_1') {
return;
}

if ($keys = $this->currentRequest->get('keys')) {
$search_data = $event->getSearch();
$search_data->setKeyword($keys);
}
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[AnalyticsEvent::NAME][] = ['setSiteSection'];
$events[AnalyticsEvent::NAME][] = ['setSearchData'];

return $events;
}
Expand Down

0 comments on commit 1c2e21e

Please sign in to comment.