Oh Dear is the all-in-one monitoring tool for your entire website. We monitor uptime, SSL certificates, broken links, scheduled tasks and more. You'll get a notifications for us when something's wrong. All that paired with a developer friendly API and kick-ass documentation. O, and you'll also be able to create a public status page under a minute. Start monitoring using our free trial now.

Easily setup and send data to Google Tag Manager in Laravel apps

Original – by Freek Van der Herten – 2 minute read

Google Tag Manager allows you to add tags to your site without editing the site code. A tag, in Google parlance, is a snippet of JavaScript that sends information to a third party, such as... Google. There are tags to install things like Analytics, Adwords or others on your site .

To use GTM you have to include a small piece of JavaScript on every page, much like what you need to do to install Google Analytics. When installed tags can be added to your site via a great looking interface. As with other Google products there are lots of options which sometimes be confusing. If you want to know more about GTM you read the official documentation.

You can also feed custom data to GTM by sending data through a dataLayer variable in javascript. Check out the developer guide to see what's possible.

My colleague Sebastian made a great package that makes installing GTM in your Laravel app a breeze. If you just want a basic installation you'll have to follow the easy install instructions and include a view in your layout.

If you want to use the dataLayer the package provides some handy methods for that. You can even define macros so you can manage the data you want to sent to GTM in one place.

You can read more instructions on how to use the package on GitHub:

https://github.com/spatie/laravel-googletagmanager

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.

Comments

What are your thoughts on "Easily setup and send data to Google Tag Manager in Laravel apps"?

Comments powered by Laravel Comments
Want to join the conversation? Log in or create an account to post a comment.