diff --git a/README.md b/README.md index cc9fc13..e36c038 100644 --- a/README.md +++ b/README.md @@ -129,23 +129,27 @@ $ga4Service->send($baseRequest); ``` At the moment, the library contains the defined structures of the following events: + | Event name | Structure | Documentation | | ---------- | --------- | --------------| -| add_payment_info | AddPaymentInfoEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#add_payment_info) -| add_shipping_info | AddShippingInfoEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#add_shipping_info) -| add_to_cart | AddToCartEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#add_to_cart) -| add_to_wishlist | AddToWishlistEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events?hl=fr&client_type=gtag#add_to_wishlist) -| begin_checkout | BeginCheckoutEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#begin_checkout) -| login | LoginEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#login) -| purchase | PurchaseEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#purchase) -| refund | RefundEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#refund) -| remove_from_cart | RemoveFromCartEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#remove_from_cart) -| search | SearchEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#search) -| select_item | SelectItemEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#select_item) -| sign_up | SignUpEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#sign_up) -| view_cart | ViewCartEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#view_cart) -| view_item | ViewItemEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#view_item) -| view_search_results | ViewSearchResultsEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#view_search_results) +| add_payment_info | AddPaymentInfoEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#add_payment_info) | +| add_shipping_info | AddShippingInfoEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#add_shipping_info) | +| add_to_cart | AddToCartEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#add_to_cart) | +| add_to_wishlist | AddToWishlistEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#add_to_wishlist) | +| begin_checkout | BeginCheckoutEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#begin_checkout) | +| login | LoginEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#login) | +| purchase | PurchaseEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#purchase) | +| refund | RefundEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#refund) | +| remove_from_cart | RemoveFromCartEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#remove_from_cart) | +| search | SearchEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#search) | +| select_item | SelectItemEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#select_item) | +| sign_up | SignUpEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#sign_up) | +| view_cart | ViewCartEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_cart) | +| view_item | ViewItemEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item) | +| view_item_list | ViewItemListEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item_list) | +| view_search_results | ViewSearchResultsEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_search_results) | +| select_promotion | SelectPromotionEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#select_promotion) | +| view_promotion | ViewPromotionEvent | [see documentation](https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_promotion) | These events are sent analogously to the examples presented above. @@ -160,7 +164,7 @@ use Br33f\Ga4\MeasurementProtocol\Dto\Event\BaseEvent; // Create Service and request same as above // ... -// Create Base Event Data (for example: 'share' event - https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#share) +// Create Base Event Data (for example: 'share' event - https://developers.google.com/analytics/devguides/collection/ga4/reference/events?sjid=17491993992317121377-NA&client_type=gtag#share) $eventName = 'share'; $anyEventData = new BaseEvent($eventName); $anyEventData diff --git a/composer.json b/composer.json index dbdb1ed..5829bbd 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,12 @@ { - "name": "br33f/php-ga4-mp", + "name": "ldani3l/php-ga4-mp", "description": "PHP GoogleAnalytics4 Measurement Protocol Library", "minimum-stability": "stable", "license": "MIT", "authors": [ { - "name": "Damian Zamojski", - "email": "damian.zamojski1@gmail.com" + "name": "Daniel Alvarez", + "email": "ingenierodaniel7@gmail.com" } ], "require": { diff --git a/src/Dto/Event/SelectPromotionEvent.php b/src/Dto/Event/SelectPromotionEvent.php new file mode 100644 index 0000000..36fe907 --- /dev/null +++ b/src/Dto/Event/SelectPromotionEvent.php @@ -0,0 +1,32 @@ +eventName, $paramList); + } +} diff --git a/src/Dto/Event/ViewPromotionEvent.php b/src/Dto/Event/ViewPromotionEvent.php new file mode 100644 index 0000000..bcc8a8a --- /dev/null +++ b/src/Dto/Event/ViewPromotionEvent.php @@ -0,0 +1,32 @@ +eventName, $paramList); + } +} diff --git a/src/Dto/Parameter/ItemParameter.php b/src/Dto/Parameter/ItemParameter.php index 8786f9e..9fc028c 100644 --- a/src/Dto/Parameter/ItemParameter.php +++ b/src/Dto/Parameter/ItemParameter.php @@ -127,6 +127,20 @@ class ItemParameter extends AbstractParameter implements HydratableInterface */ protected $itemListName; + /** + * The name of the list in which the item was presented to the user + * Not required + * @var string|null + */ + protected $promotionId; + + /** + * The name of the list in which the item was presented to the user + * Not required + * @var string|null + */ + protected $promotionName; + /** * The item variant or unique code or description for additional item details/options. * Not required @@ -171,62 +185,34 @@ public function __construct(?array $blueprint = null) */ public function hydrate($blueprint) { - if (array_key_exists('item_id', $blueprint)) { - $this->setItemId($blueprint['item_id']); - } - if (array_key_exists('item_name', $blueprint)) { - $this->setItemName($blueprint['item_name']); - } - if (array_key_exists('affiliation', $blueprint)) { - $this->setAffiliation($blueprint['affiliation']); - } - if (array_key_exists('coupon', $blueprint)) { - $this->setCoupon($blueprint['coupon']); - } - if (array_key_exists('currency', $blueprint)) { - $this->setCurrency($blueprint['currency']); - } - if (array_key_exists('discount', $blueprint)) { - $this->setDiscount($blueprint['discount']); - } - if (array_key_exists('index', $blueprint)) { - $this->setIndex($blueprint['index']); - } - if (array_key_exists('item_brand', $blueprint)) { - $this->setItemBrand($blueprint['item_brand']); - } - if (array_key_exists('item_category', $blueprint)) { - $this->setItemCategory($blueprint['item_category']); - } - if (array_key_exists('item_category2', $blueprint)) { - $this->setItemCategory2($blueprint['item_category2']); - } - if (array_key_exists('item_category3', $blueprint)) { - $this->setItemCategory3($blueprint['item_category3']); - } - if (array_key_exists('item_category4', $blueprint)) { - $this->setItemCategory4($blueprint['item_category4']); - } - if (array_key_exists('item_category5', $blueprint)) { - $this->setItemCategory5($blueprint['item_category5']); - } - if (array_key_exists('item_list_id', $blueprint)) { - $this->setItemListId($blueprint['item_list_id']); - } - if (array_key_exists('item_list_name', $blueprint)) { - $this->setItemListName($blueprint['item_list_name']); - } - if (array_key_exists('item_variant', $blueprint)) { - $this->setItemVariant($blueprint['item_variant']); - } - if (array_key_exists('location_id', $blueprint)) { - $this->setLocationId($blueprint['location_id']); - } - if (array_key_exists('price', $blueprint)) { - $this->setPrice($blueprint['price']); - } - if (array_key_exists('quantity', $blueprint)) { - $this->setQuantity($blueprint['quantity']); + $mapping = [ + 'item_id' => 'setItemId', + 'item_name' => 'setItemName', + 'affiliation' => 'setAffiliation', + 'coupon' => 'setCoupon', + 'currency' => 'setCurrency', + 'discount' => 'setDiscount', + 'index' => 'setIndex', + 'item_brand' => 'setItemBrand', + 'item_category' => 'setItemCategory', + 'item_category2' => 'setItemCategory2', + 'item_category3' => 'setItemCategory3', + 'item_category4' => 'setItemCategory4', + 'item_category5' => 'setItemCategory5', + 'promotion_id' => 'setPromotionId', + 'promotion_name' => 'setPromotionName', + 'item_list_id' => 'setItemListId', + 'item_list_name' => 'setItemListName', + 'item_variant' => 'setItemVariant', + 'location_id' => 'setLocationId', + 'price' => 'setPrice', + 'quantity' => 'setQuantity', + ]; + + foreach ($mapping as $key => $method) { + if (array_key_exists($key, $blueprint)) { + $this->$method($blueprint[$key]); + } } } @@ -298,6 +284,8 @@ public function export() 'item_category3' => $this->getItemCategory3(), 'item_category4' => $this->getItemCategory4(), 'item_category5' => $this->getItemCategory5(), + 'promotion_id' => $this->getPromotionId(), + 'promotion_name' => $this->getPromotionName(), 'item_list_id' => $this->getItemListId(), 'item_list_name' => $this->getItemListName(), 'item_variant' => $this->getItemVariant(), @@ -541,6 +529,40 @@ public function getItemListName(): ?string return $this->itemListName; } + /** + * @param string|null $promotionName + * @return ItemParameter + */ + public function setPromotionName(?string $promotionName): ItemParameter + { + $this->promotionName = $promotionName; + return $this; + } + /** + * @return string|null + */ + public function getPromotionName(): ?string + { + return $this->promotionName; + } + + /** + * @param string|null $promotionId + * @return ItemParameter + */ + public function setPromotionId(?string $promotionId): ItemParameter + { + $this->promotionId = $promotionId; + return $this; + } + /** + * @return string|null + */ + public function getPromotionId(): ?string + { + return $this->promotionId; + } + /** * @param string|null $itemListName * @return ItemParameter @@ -623,4 +645,4 @@ public function setQuantity(?float $quantity): ItemParameter return $this; } -} \ No newline at end of file +}