PHPackages                             marcwitteveen/google-tag-manager - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. marcwitteveen/google-tag-manager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

marcwitteveen/google-tag-manager
================================

Simple PHP helper functions for implementing Google Tag Manager within your website.

015PHP

Since Apr 15Pushed 6y ago1 watchersCompare

[ Source](https://github.com/marcwitteveen/google-tag-manager)[ Packagist](https://packagist.org/packages/marcwitteveen/google-tag-manager)[ RSS](/packages/marcwitteveen-google-tag-manager/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

google-tag-manager
==================

[](#google-tag-manager)

This class provides some simple PHP helper functions for implementing Google Tag Manager within your website.

Getting Started
---------------

[](#getting-started)

You can install this package using Composer by adding this line to your composer.json `require` statement.

```
"marcwitteveen/google-tag-manager": "dev-master"
```

And then run from terminal:

```
sudo composer update
```

Code Sample
-----------

[](#code-sample)

```
use MarcWitteveen\Gtm\Gtm;

Gtm::renderHeadTag('GTM-XXXXXX');
/* This will render the following code:

(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');

*/

Gtm::renderBodyTag('GTM-XXXXXX');
/* This will render the following code:

*/
```

Methods:
--------

[](#methods)

- `Gtm::renderHeadTag($container_id = "")`
- `Gtm::renderBodyTag($container_id = "")`

`renderHeadTag` Method
----------------------

[](#renderheadtag-method)

#### Description

[](#description)

Renders a Google Tag Manager container that needs to be placed as high in the of the page as possible.

#### Parameters

[](#parameters)

- `$container_id` (required): The id of your container. You can get this value from your Google Tag Manager account admin panel.

`renderBodyTag` Method
----------------------

[](#renderbodytag-method)

#### Description

[](#description-1)

Optional: Renders a Google Tag Manager container that needs to be placed immediately after the opening tag.

#### Parameters

[](#parameters-1)

- `$container_id` (required): The id of your container. You can get this value from your Google Tag Manager account admin panel.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4311096b0c9c7dc22d3486baf2a0b7f087ca78b5f8fcd4597f637829db22b65f?d=identicon)[marcwitteveen](/maintainers/marcwitteveen)

---

Top Contributors

[![marcwitteveen](https://avatars.githubusercontent.com/u/555171?v=4)](https://github.com/marcwitteveen "marcwitteveen (9 commits)")

### Embed Badge

![Health badge](/badges/marcwitteveen-google-tag-manager/health.svg)

```
[![Health](https://phpackages.com/badges/marcwitteveen-google-tag-manager/health.svg)](https://phpackages.com/packages/marcwitteveen-google-tag-manager)
```

###  Alternatives

[vinkius-labs/laravel-page-speed

Laravel Page Speed

2.5k5.4k1](/packages/vinkius-labs-laravel-page-speed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
