Membership site owners often need to track additional user data for better insights and marketing strategies. If you have the Google Analytics Integration Add On for Paid Memberships Pro, you might want to track extra details, such as a custom user field created within Paid Memberships Pro.

This guide shows you how to send custom user field information from your site to Google Analytics. You can use this information within Google Analytics to analyze engagement trends based on specific user attributes. This would allow you to improve on your marketing or offerings to current and prospective audiences or customers. 

Screenshot of featured image for 'Capture User Fields for Google Analytics Integration Add On' code recipe post

Understanding the Code Recipe

This code enables Google Analytics to track a specific custom user field when a member interacts with your site.

The function get_user_meta() fetches the custom field value (e.g., company_role) from the user’s profile. When the User Fields are created within Paid Memberships Pro, this is the “Name” within the field. 

Screenshot of user field selection

This information is stored within the user’s profile. You can view this information by navigating to Memberships > Members > Edit Member or navigate to Users > All Users > Edit User

About the Code Recipe

This code sends a Paid Memberships Pro custom user field, for example, “company_role” to Google Analytics whenever user properties are being configured for tracking.

Before implementing this code recipe:

  • You must have configured Google Analytics, Paid Memberships Pro, and the PMPro Google Analytics Add On.
  • Follow the steps to create a custom dimension for your custom user field within Google Analytics. Ensure the “Scope” is set to “User” for your custom user field.
Screenshot of new custom dimension box
Screenshot of custom definitions box with company_role selected

The Code Recipe

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

How to Customize This Code Recipe

If you need to send additional custom user fields to Google Analytics, you can modify this code recipe to track multiple user attributes. Here’s how you can extend its functionality:

  • Replace company_role on line 24 with the “Name” of the custom user field you want to track on your site.
  • Duplicate line 24 for the number of custom user fields you want to track, replacing company_role with the name of your other custom user fields

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics


Was this article helpful?
YesNo