Giter VIP home page Giter VIP logo

Comments (1)

aawnu avatar aawnu commented on June 23, 2024

Okay, you need to first populate an item, then you need to make your event and pass the item to that event, and finally add it to the Analytics call.

$item = AlexWestergaard\PhpGa4\Item::new() // This is a CLASS not an ARRAY
    ->setItemId('blabla')
    ->setCurrency('usd')
    ->setPrice(60)
    ->setQuantity(1);

$event = AlexWestergaard\PhpGa4\Event\BeginCheckout::new()
    ->{your params here}
    ->addItem($item); // <--- You need to add the item to the EVENT, not ANALYTICS

$analytics = AlexWestergaard\PhpGa4\Analytics::new('id', 'secret')
    ->setClient('bla')
    ->addEvent($event); // You need to add the EVENT to ANAYLTICS, where in EVENT contains ITEMS

$analytics->post(); // This you want a try-catch around as is throws on errors, it returns void

You can NOT add Items to ANALYTICS and you can not pass ARRAY as argument as it is validated on items->toArray() that all REQUIRED parameters are set inside of src/Helper/IOHelper.php.

--- EDIT

The reason it is separated is because you might want to sent multiple events with the same items, this way you can easliy add the items to multiple events by reference.

--- EDIT 2

This also enabled that the same events can be sent to multiple Analytics instances, for example some e-comm websites have a global tracker for all shops and then a separate tracker per shop.

from php-ga4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.