Unlocking Keyword-Level Call Tracking in WordPress: A Rank Math & GA4 Solution

If your business relies on phone calls for sales, understanding which keywords drive phone calls is crucial for optimizing campaigns and maximizing ROI. We have had multiple service organizations that relied on organic searches for acquisition and phone calls for sales. However, neither their internal call system nor their phone bank offered a means to track phone calls back to the pages they were made from or the keywords those pages relied on. Tracking phone call conversions linked to specific keywords and landing pages is vital for data-driven marketing.
If you’re using WordPress and Rank Math for SEO, there’s a clever way to track phone call conversions at the keyword level, giving you granular insights into your marketing performance.
The Challenge
Many businesses rely on phone calls as a key conversion point. However, attributing those calls to specific keywords and landing pages can be tricky. Google Analytics 4 (GA4) offers powerful event-tracking capabilities, but you need a way to bridge the gap between your keyword strategy and the phone calls generated.
The Solution: Rank Math and GA4
If you’re using WordPress and Rank Math, you can achieve this.
- Rank Math: Leverage Rank Math’s focus keyword feature to associate keywords with pages.
- Google Analytics 4: Capture the keyword and phone number directly when the user clicks the phone number link. Events are automatically tied to page URLs so there’s no need to capture the path.
Step 1: Update Your WordPress Template
For any template you wish to track keywords to phone call conversions for:
- Insert the following PHP code into your theme’s template (e.g.
single.php
)
<?php $focusKeyword = get_post_meta( get_the_ID(), 'rank_math_focus_keyword', true ); if ($focusKeyword) { echo '<span id="rank-math-focus-keyword" style="display:none;">' . esc_html( $focusKeyword ) . '</span>'; } ?>
- Add a dynamic script to the template to publish the event tracking wherever the keyword exists:
<?php function add_phone_call_tracking_script() {
if (get_post_meta( get_the_ID(), 'rank_math_focus_keyword', true )) {
?>
<script>
jQuery(document).ready(function() {
// 1. Get Focus Keyword
var focusKeyword = jQuery('#rank-math-focus-keyword').text();
// 2. GA4 Event Tracking (only if focusKeyword exists)
if (focusKeyword) {
jQuery('a[href^="tel:"]').click(function() {
var phoneNumber = jQuery(this).attr('href').replace('tel:', '');
gtag('event', 'phone_call', {
'phone_number': phoneNumber,
'keyword': focusKeyword
});
});
}
});
</script>
<?php
}
}
add_action( 'wp_footer', 'add_phone_call_tracking_script' );
Step 2: Configure Your GA4 Custom Definition and Event
Here are the steps to configure the necessary custom event in GA4 to capture the keyword, page_path, and phone_number information:
- Access Custom Definitions
- In your GA4 property, navigate to Admin (the gear icon in the bottom left corner).
- Under the Property column, click on Custom Definitions.
- Create a New Custom Event
- Click on the Create Custom Events button.
- Define the Custom Event
- Custom event name: Enter
phone_call
(or any other descriptive name you prefer). - Matching conditions:
- Click on the Add condition button.
- In the
Parameter
dropdown, select event_name. - In the
Operator
dropdown, select equals. - In the
Value
field, enter phone_call (this should match the event name you’ll use in your jQuery code).
- Parameters:
- Click on the Add parameter button twice times to add two parameters.
- For the first parameter:
- Parameter name: Enter
keyword
. - Value type: Select Text.
- Parameter name: Enter
- For the second parameter:
- Parameter name: Enter
phone_number
. - Value type: Select Text.
- Parameter name: Enter
- For the first parameter:
- Click on the Add parameter button twice times to add two parameters.
- Save the Custom Event
- Click on the Create button to save the custom event.
- Custom event name: Enter
You should be able to see the phone_call
events in GA4’s Realtime report almost immediately after a user triggers the event by clicking on a phone number link on your website. Other reports may require up to 24 hours for the data to register accurately.
Additional Notes
- If you want to track additional information related to phone calls (e.g., call duration, outcome), you can create additional custom parameters in GA4 or consider using custom dimensions.
- Always test your implementation thoroughly to ensure events are being tracked correctly and data is accurately captured in GA4.
By leveraging Rank Math’s focus keyword, a simple custom field, and GA4’s event tracking, you can achieve effective keyword-level call tracking in WordPress without additional services. This streamlined solution empowers you to understand the impact of your SEO efforts on phone call conversions, enabling data-driven optimization and improved marketing ROI.