- Configuring Google Analytics 4 Tracking with GTM
Configuring Google Analytics 4 Tracking with GTM #
You can track user searches and clicks within the Smart Search popup. This tracking data includes contextual information only and no personal user information.
Prerequisites #
- Google Analytics 4 (GA4) property set up
- Google Tag Manager (GTM) container installed on your website
- Admin access to both GA4 and GTM
Step 1: Enable Analytics in Smart Search #
In the Smart Search WordPress plugin, navigate to Smart Search → Analytics and enable Google Analytics 4 tracking.
Step 2: Set Up Google Tag Manager #
If you don’t already have a GTM container, follow Google’s setup guide.
- Select Web as the container type for your website.
- Insert the GTM script in the <head> tag of your website.
Step 3: Configure GTM Variables, Triggers, and Tags #
Follow these steps in your GTM workspace:
3.1 Create Data Layer Variables #
Navigate to Workspace → Variables → User-Defined Variables.
- Click New to create a new variable.
- Set the variable type to Data Layer Variable.
- Enter swsTerm as the Data Layer Variable Name.
- Click Save.
- Repeat steps 1–4 to create two additional variables: swsCategory and swsWidgetId.

3.2 Create a Custom Event Trigger #
Navigate to Workspace → Triggers.
- Click New to create a new trigger.
- Name the trigger swsSearch Trigger.
- Set the trigger type to Custom Event.
- Enter swsEvent as the Event Name.
- Click Save.
3.3 Create a Google Analytics Tag #
Navigate to Workspace → Tags.
- Click New to create a new tag.
- Name the tag Analytics – Smart Search.
- For tag type, select Google Analytics → Google Analytics: GA4 Event.
- Find your Measurement ID in your Google Analytics dashboard (use the search bar to locate it).
- Set the Event Name to swsEvent.
- In the Event Parameters section, add the two variables: swsTerm and swsCategory.
- Scroll to the Triggering section and select swsSearch Trigger.
- Click Save.

3.4 Publish Changes #
Click the Submit button in the top right corner to publish your changes to the website.
Step 4: Create Custom Dimensions in Google Analytics #
In Google Analytics, navigate to Admin → Custom Definitions → Create Custom Dimension.
Create custom dimensions for each variable: swsTerm, swsCategory, and swsWidgetId.
⚠ Important: Data will only appear in these custom dimensions 24–48 hours after creation.

Step 5: Create a Report in Google Analytics #
5.1 Create a Blank Exploration #
In Google Analytics 4, click Explore in the left-hand menu and select Blank Exploration.
5.2 Import Dimensions and Metrics #
In the Dimensions block:
- Click the + icon.
- Search for and select your custom dimensions: swsTerm, swsCategory, swsWidgetId, and Event name.
- Click Import.
In the Metrics block:
- Click the + icon.
- Select Event count.
- Click Import.
5.3 Set Up the Table #
Drag and drop the custom dimensions into the Rows section:
swsTerm, swsCategory, and swsWidgetId will appear as side-by-side columns in the table.
Drag and drop Event count into the Values section.

5.4 Apply a Filter #
To display only Smart Search events:
- Scroll down to the Filters section.
- Select Event name.
- Set the match type to exactly matches and type swsEvent.

5.5 Save Your Report #
In the Exploration Name field, enter a descriptive name for your report so you can easily find it later.
Event Category Reference #
Smart Search generates the following event categories:
|
Event Category |
Description |
|
[Search term] has results |
User viewed search results |
|
[Search term] no results |
User viewed the “no results” message |
|
[Found Suggestions] link click |
User clicked on a suggestion link |
|
[Found Suggestions] add-to-cart click |
User clicked on a suggestion’s “Add to Cart” button |
|
[View All] button click |
User clicked on the “View All” button |
|
[Promo banner] link click |
User clicked on a banner link in the fullscreen popup |
|
[Selected Categories] link click |
User clicked on a category in the fullscreen popup |
|
[Recommended Products] link click |
User clicked on a recommended product in the fullscreen popup |
You can filter your report by specific event categories using the Filters option in your exploration.