Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

begin checkout #55

Closed
srakl opened this issue Jun 25, 2023 · 2 comments
Closed

begin checkout #55

srakl opened this issue Jun 25, 2023 · 2 comments
Labels
question Further information is requested wontfix This will not be worked on

Comments

@srakl
Copy link

srakl commented Jun 25, 2023

Hi, is this how to do a begin checkout in the backend?

use AlexWestergaard\PhpGa4\Exception;
use AlexWestergaard\PhpGa4\Analytics;
use AlexWestergaard\PhpGa4\Event\BeginCheckout;
use AlexWestergaard\PhpGa4\Item;

try {
            // If gtag.js, this can be the _ga or _gid cookie
            // This can be any kind of session identifier
            $session = $_COOKIE['_ga'] ?? $_COOKIE['_gid'] ?? $_COOKIE['PHPSESSID'];

            $analytics = Analytics::new( 'G-XXXXXXXX','xYzzX_xYzzXzxyZxX')
            ->setClientId($session);

            $analytics->addEvent(new BeginCheckout);
            $analytics->setCurrency('usd');
            $analytics->setValue('60.00');
            $analytics->addItem([
                'item_id' => 'bla bla',
                'currency'=> 'USD',
                'price'   =>'60.00',
                'quantity'=> 1
            ]);
            $analytics->post();
        } catch (Exception\Ga4Exception $exception) {
            // Handle exception
            if (YII_DEBUG) dd($exception);
            Yii::error($exception);
        }

i'm getting this error

AlexWestergaard\PhpGa4\Exception\Ga4IOException#1
(
    [*:message] => 'Missing required parameter: items'
   .....
   .....

how do i fix this? Thank you.

@aawnu
Copy link
Owner

aawnu commented Jun 25, 2023

If you follow the code then you will see there is 3 layers.

Analytics[ Events[ Items ] ] ]

Add src/Item.php to your src/Event/BeginCheckout.php event, then add the event to src/Analytics.php.

You should not be able to addItem on Analytics, if this is doable then I will fix it later.

@aawnu aawnu closed this as completed Jun 25, 2023
@aawnu
Copy link
Owner

aawnu commented Jun 25, 2023

I just checked, you can not addItem on Analytics you just never get that far because you throw on addEvent, you're IDE should tell you as well.

Repository owner locked as resolved and limited conversation to collaborators Jun 25, 2023
@aawnu aawnu added question Further information is requested wontfix This will not be worked on labels Jun 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants