상세 컨텐츠

본문 제목

[dataLayer] How to Configure a dataLayer (e.g.)

GA4 & GTM

by datamaster23 2023. 6. 13. 23:41

본문

Question 

I would like to configure a dataLayer as shown below and connect it to Google Analytics (GA) in Google Tag Manager (GTM) using the "Google Analytics: GA4 Event" tag type. While I have assigned names to the variables mentioned, I would prefer to use built-in variables whenever available. Could you please provide me with step-by-step instructions on how to accomplish this?

 

-Event name: all_button_click

-Trigger type: click

-Variable 1. clicked_url : page URL on which the button is clicked.

e.g. The page URL on which "Join us", "Subscribe" button has been clicked

 

-Variable 2. button_name: The button text

e.g. "Twitter, Instagram, Linkedin, Tiktok", "New York, Minneapolis, London,,…"

 

-Variable 3. selected_item: The selected item amongst drop-down menu

e.g. "Afghanistan" amongst list of countries in "Select country" drop-down

 

-dataLayer:

 

window.dataLayer.push({

"event":"all_button_click",

"clicked_url":$clicked_url,

"button_name":$button_name,

"selected_item""$selected_item })

 

Answer

To configure the dataLayer push and connect it with Google Analytics in GTM using the correct built-in variable,

please follow these instructions:

 

Step 1: Set Up Google Analytics in GTM

 

Log in to your GTM account and navigate to the container where you want to configure the dataLayer push.

Go to "Tags" in the left sidebar and click on the "New" button to create a new tag.

Give the tag a descriptive name in the "Tag Name" field.

In the "Tag Configuration" section, click on the tag type selection field and choose "Google Analytics: GA4 Event".

Step 2: Connect GTM to Google Analytics

 

In the "Measurement ID" field, enter your Google Analytics Measurement ID. It should be in the format "G-XXXXXXXXXX".

Configure other settings as needed, such as enabling Enhanced Measurement if applicable.

Save the tag configuration.

Step 3: Configure Built-in Variables

 

Go to "Variables" in the left sidebar and review the available built-in variables.

Ensure that the following built-in variables are enabled and configured correctly:

"Page URL" for capturing the clicked URL (clicked_url)

"Click Text" for capturing the button text (button_name)

"Form Element" for capturing the selected option in the drop-down menu (selected_item)

 

Step 4: Configure the Tag

 

Go back to the previously created tag (Google Analytics: GA4 Event tag) and scroll down to the "Event Parameters" section.

In the "Event Name" field, enter all_button_click.

Click on the "Add Row" button to add a new parameter.

In the "Parameter Name" column, enter clicked_url.

In the "Value" column, select the "Page URL" built-in variable from the dropdown.

Add another row for the button_name parameter:

In the "Parameter Name" column, enter button_name.

In the "Value" column, select the "Click Text" built-in variable from the dropdown.

Add a row for the selected_item parameter:

In the "Parameter Name" column, enter selected_item.

In the "Value" column, select the "Form Element" built-in variable from the dropdown.

Step 5: Set Up Trigger

 

In the "Triggering" section of the tag configuration, click on the pencil icon next to "Triggering".

Choose the appropriate trigger based on when you want this tag to fire. For example, you might choose a "Click" trigger to fire the tag when a specific button or link is clicked.

Step 6: Save and Publish

 

Click on the "Save" button to save the tag configuration.

After saving, click on the "Submit" button in the upper right corner of the GTM interface to publish the changes to your container.

That's it! Once the tag is published, it will fire whenever the specified trigger conditions are met. The dataLayer push will be executed, and the event with the associated clicked_url, button_name, and selected_item data will be sent to Google Analytics for tracking.

 

Remember to test the implementation thoroughly to ensure that the dataLayer push and Google Analytics tracking are working as expected.

관련글 더보기