Comments (1)
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)
- Update GA4Exception with improved error reporting
- Problem with Event Refund HOT 3
- Move support up to PHP 8+
- Add import method of array values
- Enable debug_mode support? HOT 12
- Refactor structure and use of facades/abstraction
- rationale for Analytics::new() HOT 2
- Add document title HOT 3
- Add core events of GA.js/GTAG.js as SST-Events HOT 1
- php-ga4: ^1.1 - Events are not appearing in GA4 realtime . HOT 9
- begin_checkout HOT 1
- begin checkout HOT 2
- README _gid cookie question HOT 1
- question: How to get data to show up in debug? HOT 3
- Dashboard not reflecting the posted report HOT 1
- User Properties - Question HOT 1
- Status of page_view event HOT 2
- User location HOT 1
- Client id must have been created by gtag.js? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-ga4.