View Categories

Analytics

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.

  1. Click New to create a new variable.
  2. Set the variable type to Data Layer Variable.
  3. Enter swsTerm as the Data Layer Variable Name.
  4. Click Save.
  5. Repeat steps 1–4 to create two additional variables: swsCategory and swsWidgetId.

 

GTM-variable

 

3.2 Create a Custom Event Trigger #

Navigate to Workspace → Triggers.

  1. Click New to create a new trigger.
  2. Name the trigger swsSearch Trigger.
  3. Set the trigger type to Custom Event.
  4. Enter swsEvent as the Event Name.
  5. Click Save.

 

3.3 Create a Google Analytics Tag #

Navigate to Workspace → Tags.

  1. Click New to create a new tag.
  2. Name the tag Analytics – Smart Search.
  3. For tag type, select Google Analytics → Google Analytics: GA4 Event.
  4. Find your Measurement ID in your Google Analytics dashboard (use the search bar to locate it).
  5. Set the Event Name to swsEvent.
  6. In the Event Parameters section, add the two variables: swsTerm and swsCategory.
  7. Scroll to the Triggering section and select swsSearch Trigger.
  8. Click Save.

 

GTM-tag

 

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.

 

add-custom-dimension

 

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:

  1. Click the + icon.
  2. Search for and select your custom dimensions: swsTerm, swsCategory, swsWidgetId, and Event name.
  3. Click Import.

In the Metrics block:

  1. Click the + icon.
  2. Select Event count.
  3. 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.

 

creating-report

 

5.4 Apply a Filter #

To display only Smart Search events:

  1. Scroll down to the Filters section.
  2. Select Event name.
  3. Set the match type to exactly matches and type swsEvent.

 

creating-report

 

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.