sy / google-analytics
Google Analytics web component
2.0.0
2022-10-16 20:28 UTC
Requires
- php: >=5.6.0
- sy/html: ^2
This package is auto-updated.
Last update: 2024-10-17 00:41:10 UTC
README
A web component for adding Google Analytics on your website
Installation
Install the latest version with
$ composer require sy/google-analytics
Basic Usage
<?php use Sy\Component\Html\Page; use Sy\Component\Web\GoogleAnalytics; require __DIR__ . '/../vendor/autoload.php'; $ga = new GoogleAnalytics('ID-XXXXX'); $page = new Page(); $page->addBody($ga); echo $page;
Output:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="https://www.googletagmanager.com/gtag/js?id=ID-XXXXX" async></script> </head> <body> <script type="module"> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'ID-XXXXX');</script> </body> </html>