{"id":21089779,"url":"https://github.com/freshbitsweb/laravel-google-analytics-4-measurement-protocol","last_synced_at":"2025-09-05T21:33:04.649Z","repository":{"id":39662594,"uuid":"346673424","full_name":"freshbitsweb/laravel-google-analytics-4-measurement-protocol","owner":"freshbitsweb","description":"A Laravel package to use Measurement Protocol for Google Analytics 4","archived":false,"fork":false,"pushed_at":"2025-02-26T05:43:04.000Z","size":22,"stargazers_count":19,"open_issues_count":2,"forks_count":13,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-25T09:43:45.108Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/freshbitsweb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-11T11:05:42.000Z","updated_at":"2025-07-09T07:44:25.000Z","dependencies_parsed_at":"2025-03-01T00:16:27.961Z","dependency_job_id":"eb863b44-d7bf-457a-b0d7-d64ceb0bdf9d","html_url":"https://github.com/freshbitsweb/laravel-google-analytics-4-measurement-protocol","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"6ef1f944249be76db81e7d5efb4ca1e4f5bd595e"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/freshbitsweb/laravel-google-analytics-4-measurement-protocol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshbitsweb%2Flaravel-google-analytics-4-measurement-protocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshbitsweb%2Flaravel-google-analytics-4-measurement-protocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshbitsweb%2Flaravel-google-analytics-4-measurement-protocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshbitsweb%2Flaravel-google-analytics-4-measurement-protocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freshbitsweb","download_url":"https://codeload.github.com/freshbitsweb/laravel-google-analytics-4-measurement-protocol/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freshbitsweb%2Flaravel-google-analytics-4-measurement-protocol/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273826138,"owners_count":25175232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T21:31:29.154Z","updated_at":"2025-09-05T21:33:04.620Z","avatar_url":"https://github.com/freshbitsweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Plant a Tree](https://img.shields.io/badge/dynamic/json?color=brightgreen\u0026label=Plant%20a%20Tree\u0026query=%24.total\u0026url=https%3A%2F%2Fpublic.offset.earth%2Fusers%2Ftreeware%2Ftrees)](https://plant.treeware.earth/freshbitsweb/laravel-google-analytics-4-measurement-protocol)\n\n# Laravel Google Analytics 4 Measurement Protocol\nA Laravel package to use [Measurement Protocol for Google Analytics 4](https://developers.google.com/analytics/devguides/collection/protocol/ga4).\n\n## Introduction\nThis package allows you to post events to Google Analytics 4 from your Laravel backend.\n\n## Supported Laravel versions\n- Laravel 7.x\n- Laravel 8.x\n- Laravel 9.x\n- Laravel 10.x\n- Laravel 11.x\n- Laravel 12.x\n\n## Installation\n1) Install the package by running this command in your terminal/cmd:\n```bash\ncomposer require freshbitsweb/laravel-google-analytics-4-measurement-protocol\n```\n\n2) Set `MEASUREMENT_ID` and `MEASUREMENT_PROTOCOL_API_SECRET` in your .env file.\nYou can get them from: Google Analytics \u003e Admin \u003e Data Streams \u003e [Select Site] \u003e Measurement Protocol API secrets\n\n3) Optional: You can publish the config file by running this command in your terminal/cmd:\n```bash\nphp artisan vendor:publish --tag=google-analytics-4-measurement-protocol-config\n```\n\n4) `client_id` is required to post an event to Google Analytics. This package provides a Blade component which you can put in your layout file after the Google Analytics Code tracking code. It makes a POST request to the backend to store the client id in the session which is later used to post events to Google Analytics 4.\n\n```html\n\u003c!-- Google Analytics Code --\u003e\n\u003cx-google-analytics-client-id /\u003e\n\u003c!-- \u003c/head\u003e --\u003e\n```\n\nThe other option is to call the `setClientId($clientId)` method on the `GA4` facade everytime before calling the `postEvent()` method.\n\n## Usage\n\nYou can simple call `GA4::postEvent($eventData)` from anywhere in your backend to post event to Google Analytics 4. `$eventData` contains the name and params of the event as per this [reference page](https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference/events#login). For example:\n\n```php\nGA4::postEvent([\n    'name' =\u003e 'login',\n    'params' =\u003e [\n        'method' =\u003e 'Google',\n    ],\n]);\n```\n\n`postEvent()` method will return an array with the status of the request.\n\n### Debugging Mode\n\nYou can also enable [debugging mode](https://developers.google.com/analytics/devguides/collection/protocol/ga4/validating-events) by calling `enableDebugging()` method before calling the `postEvent()` method. Like so - `GA4::enableDebugging()-\u003epostEvent($eventData)`. The `postEvent()` method will return the response (array) from Google Analytics request in that case.\n\n## Authors\n\n* [**Gaurav Makhecha**](https://github.com/gauravmak) - *Initial work*\n\nSee also the list of [contributors](https://github.com/freshbitsweb/laravel-google-analytics-4-measurement-protocol/graphs/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n\n## Treeware\n\nYou're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree.\n\nIt’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to \u003ca href=\"https://www.bbc.co.uk/news/science-environment-48870920\"\u003eplant trees\u003c/a\u003e. If you contribute to our forest you’ll be creating employment for local families and restoring wildlife habitats.\n\nYou can buy trees at for our forest here [offset.earth/treeware](https://plant.treeware.earth/freshbitsweb/laravel-google-analytics-4-measurement-protocol)\n\nRead more about Treeware at [treeware.earth](http://treeware.earth)\n\n## Special Thanks to\n\n* [Laravel](https://laravel.com) Community\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreshbitsweb%2Flaravel-google-analytics-4-measurement-protocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreshbitsweb%2Flaravel-google-analytics-4-measurement-protocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreshbitsweb%2Flaravel-google-analytics-4-measurement-protocol/lists"}