aawnu / php-ga4

PHP Wrapper for Google Analytics 4 with Server Side Tracking

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add import method of array values

aawnu opened this issue · comments

I would like to add arraycreation of events and items, where it is currently done through chained events only.

Currently:

use AlexWestergaard\PhpGa4\Event;

$event = Event\ViewCart::new()
    ->setCurrency('EUR')
    ->setValue(10.00);

I would like to also allow:

use AlexWestergaard\PhpGa4\Event;

$event = Event\ViewCart::fromArray([
    'currency' => 'DKK', // eq ViewCart::$currency
    'value' => 10.00', // eq ViewCart::$value
]);

It should also have proper validation for sub-model imports, so that ViewCart::addItem(Item $item) would be triggered on <items=>Object|Array> either by executing addItem if object or import through item::fromArray()->toArray() if Array.

the purpose of this should be the ability to build larger datasets and then import as array post-process rather than in-process.