From f2350b4e564a5e8d13d5d6afcde3a2fe81546628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Wed, 19 Jun 2019 09:26:37 +0200 Subject: [PATCH] Append utm parameter to urls in google business feed --- .../Classes/Controller/ResellerController.php | 19 ++++++++-- .../Classes/Domain/Serialization/Product.php | 6 ++-- .../Classes/Service/ResellerDataService.php | 36 +++++++++++++++---- .../Classes/Utility/SerializationUtility.php | 13 +++++-- 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php b/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php index 211b4160..f9da37ae 100644 --- a/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php +++ b/public/typo3conf/ext/ep_products/Classes/Controller/ResellerController.php @@ -95,7 +95,12 @@ class ResellerController extends ActionController public function copypasteAction(Reseller $reseller, Product $product) { if (!$reseller->getProducts()->contains($product)) { - $this->redirect('list', null, null, [ 'reseller' => $reseller ]); + $this->redirect( + 'list', + null, + null, + [ 'reseller' => $reseller ] + ); } $productData = $this->resellerDataService->preprocessSingle($product, $reseller); @@ -126,7 +131,11 @@ class ResellerController extends ActionController header('Expires: 0'); header('Pragma: public'); - echo $serializer->serialize($data, 'xml', [ 'xml_encoding' => 'utf-8', 'xml_format_output' => true ]); + echo $serializer->serialize( + $data, + 'xml', + [ 'xml_encoding' => 'utf-8', 'xml_format_output' => true ] + ); exit(); } @@ -143,7 +152,11 @@ class ResellerController extends ActionController throw new InvalidArgumentValueException(); } - $data = $this->resellerDataService->preprocessAll($reseller, static::$imageDimensions[$type]); + $data = $this->resellerDataService->preprocessAll( + $reseller, + static::$imageDimensions[$type], + $type + ); $filename = sprintf('export_%s_%s.csv', $reseller->getCode(), date('Y-m-d')); diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Serialization/Product.php b/public/typo3conf/ext/ep_products/Classes/Domain/Serialization/Product.php index 924420e4..58a4e9b2 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Serialization/Product.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Serialization/Product.php @@ -35,12 +35,14 @@ class Product /** * @param \EP\EpProducts\Domain\Model\Product $entity * @param array $imageProcessingInstructions + * @param array $queryData * @return array */ public static function fromEntity ( \EP\EpProducts\Domain\Model\Product $entity, - array $imageProcessingInstructions = null + array $imageProcessingInstructions = null, + array $queryData = [] ) { $product = [ @@ -75,7 +77,7 @@ class Product $product['video'] = $entity->getVideo(); $link = $entity->getExternalLink() ?: $entity->getDetailPage(); - $product['link'] = SerializationUtility::generateLink($link); + $product['link'] = SerializationUtility::generateLink($link, $queryData); $product['region'] = Region::fromEntity($entity->getRegion()); $product['city'] = City::fromEntity($entity->getCity()); diff --git a/public/typo3conf/ext/ep_products/Classes/Service/ResellerDataService.php b/public/typo3conf/ext/ep_products/Classes/Service/ResellerDataService.php index 08253ca4..170dbb0f 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/ResellerDataService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/ResellerDataService.php @@ -32,6 +32,8 @@ use EP\EpProducts\Domain\Model\Product; use EP\EpProducts\Domain\Model\Reseller; use EP\EpProducts\Domain\Repository\ProductRepository; use EP\EpProducts\Domain\Serialization\Date; +use EP\EpProducts\Domain\Serialization\Hotel as SerializedHotel; +use EP\EpProducts\Domain\Serialization\Product as SerializedProduct; use EP\EpProducts\Domain\Serialization\Room; use EP\EpProducts\Traits\DbConnectionTrait; use EP\EpProducts\Utility\BookingUrlUtility; @@ -58,10 +60,11 @@ class ResellerDataService implements SingletonInterface /** * @param Reseller $reseller * @param array $imageProcessingInstructions + * @param string $type * @return array * @throws \Doctrine\DBAL\DBALException */ - public function preprocessAll(Reseller $reseller, array $imageProcessingInstructions = null) + public function preprocessAll(Reseller $reseller, array $imageProcessingInstructions = null, $type = 'facebook') { $data = []; $products = $reseller->getProducts(); @@ -69,7 +72,12 @@ class ResellerDataService implements SingletonInterface foreach ($products as $product) { /** @var Product $product */ - $data['product'][] = $this->preprocessSingle($product, $reseller, $imageProcessingInstructions); + $data['product'][] = $this->preprocessSingle( + $product, + $reseller, + $imageProcessingInstructions, + $type + ); } return $data; @@ -79,12 +87,28 @@ class ResellerDataService implements SingletonInterface * @param Product $product * @param Reseller $reseller * @param array $imageProcessingInstructions + * @param string $type * @return array * @throws \Doctrine\DBAL\DBALException */ - public function preprocessSingle(Product $product, Reseller $reseller, array $imageProcessingInstructions = null) - { - $data = \EP\EpProducts\Domain\Serialization\Product::fromEntity($product, $imageProcessingInstructions); + public function preprocessSingle( + Product $product, + Reseller $reseller, + array $imageProcessingInstructions = null, + $type = 'facebook' + ) { + $queryData = $type !== 'google' ? [] : [ + 'utm_source' => 'google', + 'utm_medium' => 'cpc', + 'utm_campaign' => 'dynamisches-remarketing', + 'utm_content' => $product->getName(), + ]; + + $data = SerializedProduct::fromEntity( + $product, + $imageProcessingInstructions, + $queryData + ); $hotels = $product->getHotels(); $paCode = $reseller->getPaCode(); @@ -92,7 +116,7 @@ class ResellerDataService implements SingletonInterface foreach ($hotels as $hotel) { /** @var Hotel $hotel */ - $hotelData = \EP\EpProducts\Domain\Serialization\Hotel::fromEntity($hotel); + $hotelData = SerializedHotel::fromEntity($hotel); $dates = $this->productRepository->getDatesForExport($product, $hotel); $hotelData['dates']['date'] = $this->preprocessDates($dates, $paCode); $data['hotels']['hotel'][] = $hotelData; diff --git a/public/typo3conf/ext/ep_products/Classes/Utility/SerializationUtility.php b/public/typo3conf/ext/ep_products/Classes/Utility/SerializationUtility.php index e331d6be..bf98415a 100644 --- a/public/typo3conf/ext/ep_products/Classes/Utility/SerializationUtility.php +++ b/public/typo3conf/ext/ep_products/Classes/Utility/SerializationUtility.php @@ -89,16 +89,25 @@ class SerializationUtility /** * @param string $parameter + * @param array $queryData * @return string */ - public static function generateLink($parameter) + public static function generateLink($parameter, array $queryData = []) { if (static::$contentObject === null) { /** @var ContentObjectRenderer $contentObject */ static::$contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class); } - return static::$contentObject->typoLink_URL([ 'parameter' => $parameter, 'forceAbsoluteUrl' => true ]); + $url = static::$contentObject->typoLink_URL([ 'parameter' => $parameter, 'forceAbsoluteUrl' => true ]); + + if ($queryData) { + $query = http_build_query($queryData); + $divider = strpos($url, '?') !== false ? '&' : '?'; + $url .= $divider . urlencode($query); + } + + return $url; } /**