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

Add debug section to readme #65

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ composer require alexwestergaard/php-ga4
- [Frontend](#frontend)
- [Backend](#backend)
- [Custom Events](#custom-events)
- [Debug](#debug)
- [Documentation](#documentation)

## GDPR Notice
Expand Down Expand Up @@ -305,6 +306,39 @@ class ExampleEvent extends AlexWestergaard\PhpGa4\Helper\EventHelper
}
```

## Debug

Measurement protocol for GA4 has a debug functionality that can be enabled with the `debug` parameter in the constructor.

```php
$analytics = Analytics::new(
measurement_id: 'G-XXXXXXXX',
api_secret: 'xYzzX_xYzzXzxyZxX',
debug: true
);
```

Once set, events are sent to `https://www.google-analytics.com/debug/mp/collect` which will return a validation response such as

```json
{
"validationMessages": [
{
"fieldPath": "events",
"description": "Event at index: [0] has invalid name [_badEventName]. Names must start with an alphabetic character.",
"validationCode": "NAME_INVALID"
}
]
}
```

This library already validates that events are properly formatted and it is unlikely, you will experience any validation messages.

Two important points:

- Events sent to the Validation Server will not show up in reports.
- There is no way for events sent through measurement protocol to show up in the `debugView` in Google Analytics Admin.

## Documentation

- [Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/ga4)
Expand Down