PHPackages                             setono/google-analytics-server-side-tracking-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. setono/google-analytics-server-side-tracking-bundle

ActiveSymfony-bundle

setono/google-analytics-server-side-tracking-bundle
===================================================

A Symfony bundle that allows you to track your visitors server side instead of client side

v0.3.9(3y ago)422.3k2[6 PRs](https://github.com/Setono/GoogleAnalyticsServerSideTrackingBundle/pulls)2MITPHPPHP &gt;=7.4

Since Sep 13Pushed 2y ago2 watchersCompare

[ Source](https://github.com/Setono/GoogleAnalyticsServerSideTrackingBundle)[ Packagist](https://packagist.org/packages/setono/google-analytics-server-side-tracking-bundle)[ RSS](/packages/setono-google-analytics-server-side-tracking-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (36)Versions (20)Used By (2)

Symfony Google Analytics Server Side Tracking Bundle
====================================================

[](#symfony-google-analytics-server-side-tracking-bundle)

[![Latest Version](https://camo.githubusercontent.com/a03ed42b67a45bd905cff796609b848d34d9b9e30b6643662b4df87472038166/68747470733a2f2f706f7365722e707567782e6f72672f7365746f6e6f2f676f6f676c652d616e616c79746963732d7365727665722d736964652d747261636b696e672d62756e646c652f762f737461626c65)](https://packagist.org/packages/setono/google-analytics-server-side-tracking-bundle)[![Software License](https://camo.githubusercontent.com/40a85c14988b922eddcc2eb9a2694f54ae4c656c13ec016175c47308f240d925/68747470733a2f2f706f7365722e707567782e6f72672f7365746f6e6f2f676f6f676c652d616e616c79746963732d7365727665722d736964652d747261636b696e672d62756e646c652f6c6963656e7365)](LICENSE)[![Build Status](https://github.com/Setono/GoogleAnalyticsServerSideTrackingBundle/workflows/build/badge.svg)](https://github.com/Setono/GoogleAnalyticsServerSideTrackingBundle/actions)

Use this bundle to track your visitors with Google Analytics, but using server side integration instead of the usual client side integration.

This bundle is based on the [Google Analytics measurement protocol library](https://github.com/Setono/google-analytics-measurement-protocol)which in turn is based on the Universal Analytics solution from Google. The new GA4 tracking solution will be implemented when it's feature complete and out of beta.

Installation
------------

[](#installation)

This bundle also depends on the [Client Id Bundle](https://github.com/Setono/ClientIdBundle) and the [Consent Bundle](https://github.com/Setono/ConsentBundle), which generates client ids and provides consent services respectively. If you're not bound by the EU cookie laws, take a look at the [configuration](https://github.com/Setono/ConsentBundle#configuration)of the Consent Bundle to have consent granted by default.

To install this bundle, simply run:

```
composer require setono/google-analytics-server-side-tracking-bundle
```

This will install the bundle and enable it if you're using Symfony Flex. If you're not using Flex, add the bundle manually to `bundles.php` instead.

### Create migration

[](#create-migration)

Hits are saved in the database, so you need to create a migration file:

```
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
```

Configuration
-------------

[](#configuration)

To enable the tracking, you need to supply Google Analytics properties to track:

```
# config/packages/setono_google_analytics_server_side_tracking.yaml
setono_google_analytics_server_side_tracking:
    properties:
        - "UA-123456-78"
        - "UA-345656-81" # Notice you can add as many properties as you'd like
```

If you have your properties stored somewhere else, i.e. in a database, you can just implement the [`Setono\GoogleAnalyticsServerSideTrackingBundle\Provider\PropertyProviderInterface`](src/Provider/PropertyProviderInterface.php)which returns a list of properties.

You can also configure the minimum amount of seconds before hits are sent to Google:

```
# config/packages/setono_google_analytics_server_side_tracking.yaml
setono_google_analytics_server_side_tracking:
    send_delay: 600 # Wait a minimum of 10 minutes before sending a hit
```

Usage
-----

[](#usage)

Out of the box, the bundle will start tracking visitors just like the client side integration will, but just as with the client side integration you may want to add custom tracking specific to your application. Here's an example of the ecommerce event `Purchase`:

```
