Introduction:

Google Provides Google Analytics to track our website users and its data. By integrating the GA with our application, we can track our application usage. This document clearly explains how integration is done step by step.

Prerequisite:

Active google account.

Creating Account in Analytics:

Visit the link:

https://analytics.google.com/

  • If this is your first time creating an Analytics account, under Welcome to Google Analytics, we should click Start measuring.
  • If you already have an Analytics account and want to create a new one, in Admin, in the Account column, click Create Account.

The Account name is our choice. After Creating Account, we can create Stream after entering the site. Can Give “Skip for now” after creating the account.

After Giving Skip Now, we need to select “Continue to Home”.

Creating Stream/Property:

If we have already created the account, we need to select Admin in the bottom left corner of the page.

Under Create Property on the Right side, we have to select Data Streams.

It will ask for the platform whether we are creating a stream for the Web, Android app, or IOS app. We need to select Web for our application. After Selecting Web, we will get a separate tab to enter the Stream Details.

In the Website URL, we need to enter the correct URL for which we need to collect data. We can give the stream name of our choice.

If we click Create Stream, we will get the tab with information of Measurement ID. This ID is essential to monitor the site.

We can view these details under Data Stream under the property we have created. We can always get the measurement ID from there.

Google Tag Manager:

The Next step is to set up Google Analytics 4 using Google Tag manager. Next, we need to create a container in Google Tag Manager. We can enter the Google tag manager by clicking the icon present on the Home page under the account name.

After entering Google Tag Manager, We need to click Create Account, which is in Top Right Corner. For Creating New Account, Enter the required details. Target Platform Should be Web.

After Entering Required details, Click Create Button. This will give certain code that should be pasted in our source code. We can copy this or can get it later if we click the ID. We will get the Home Page. If we click on the id with “GTM-XXXXXXX” we can get the code to paste in our source code. We can get it anytime.

Installing Google Tag Manager In code:

  • There will be two sections of codes here in Google Tag Manager. Head and Body Section. We need to paste them under respective section in the index file.
  • Another way is we can create that as HTML code in a separate file and include that in index file. 

Both ways will work perfectly.

Next, we have to enter to “Tags” in left side panel. Here we need to click the Option New.

We will get Untitled Tag screen opened. If we click on Tag configuration, we have to select which Google Analytics we need. We need to select Google Analytics and then Google Analytics GA4 Event.

After Selecting, we need to Enter the Measurement ID we got while creating the stream. This is the connection we are establishing to the website and analytics. So, it should be correct.

Next, we have to select triggering. Select All Pages here. Then Click on Create. The Tag will be created under Tags.

Next, we have to Publish the changes we have made till now. There will be Submit Button on the Top Right Corner. Just click on Submit and then Publish.

While clicking Publish, it will ask for description. We don’t have to enter anything. Click Continue and that will be live.

Then there is the Preview Button near Submit. By Clicking Preview Button and then if we enter the Website URL here and click connect, the website is now ready to collect the analytics data.

Conclusion:

By Following all steps, we can track our website users and analytics data for a PHP Laravel web application.

Leave a Reply