How to track custom user properties in Google Tag Manager

Author:

Tracking custom user properties in Google Tag Manager (GTM) allows you to capture specific user data (such as user preferences, behavior, or any other custom attributes) and send them to analytics or marketing platforms, like Google Analytics, Facebook, or other third-party services. Custom user properties can enhance your ability to segment users, understand their behavior, and improve marketing efforts.

Here’s how to track custom user properties in Google Tag Manager:

Step 1: Identify the Custom User Property

The first step is to identify which custom user property you want to track. This could be anything specific to your website or application, such as:

  • User ID (from a logged-in user)
  • User type (e.g., free or premium users)
  • Membership status (active, inactive, expired)
  • Referral source
  • User behavior attributes (such as “number of purchases” or “pages viewed”)

These values might be stored in variables on the page or in a data layer.

Step 2: Use the Data Layer or JavaScript to Capture Custom User Properties

Option 1: Using the Data Layer

If you have custom user properties that are available in the Data Layer (the JavaScript object that GTM can access), you can push these values to the Data Layer for use within GTM.

  1. Push custom properties to the Data Layer: To do this, you need to include the custom property data on your webpage when the page loads or when a specific event occurs.

    Example of pushing custom properties to the Data Layer:

    javascript
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
    'event': 'userData',
    'userId': '12345',
    'userType': 'premium',
    'membershipStatus': 'active'
    });

    In this example, the custom user properties (userId, userType, and membershipStatus) are pushed into the Data Layer.

  2. Access Data Layer variables in GTM: Once the custom properties are pushed to the Data Layer, you can create GTM variables to capture these values.
    • In GTM, go to Variables > New > Data Layer Variable.
    • Name the variable, e.g., userId, and set the Data Layer Variable Name to the corresponding key from the Data Layer (e.g., userId).
    • Click Save.
  3. Repeat for other custom properties: Create additional Data Layer variables for userType and membershipStatus using the same process.

Option 2: Using JavaScript Variables

If custom properties are not in the Data Layer but are accessible through the page’s JavaScript (e.g., in a global JavaScript variable), you can use a JavaScript Variable to capture those properties.

  1. Create a JavaScript Variable in GTM:
    • In GTM, go to Variables > New > JavaScript Variable.
    • Set the Variable Name to the JavaScript variable that holds the custom property. For example, if the custom user property userId is stored in window.userInfo.userId, set the variable to window.userInfo.userId.
  2. Repeat for other custom properties: You can create additional JavaScript Variables for other properties such as userType or membershipStatus.

Step 3: Send Custom Properties to Analytics Platforms (e.g., Google Analytics)

Once you’ve captured the custom properties in GTM, you can send them to your analytics or marketing platform.

Example: Send Custom Properties to Google Analytics

  1. Create a Google Analytics Tag in GTM:
    • In GTM, go to Tags > New > Tag Configuration > Google Analytics: Universal Analytics (or Google Analytics 4 if you’re using that version).
    • Select the appropriate Tracking Type (e.g., Page View, Event).
  2. Send Custom Properties as Custom Dimensions: To send the custom properties (e.g., userId, userType, membershipStatus) as custom dimensions in Google Analytics:
    • Under More Settings > Custom Dimensions (Universal Analytics) or Event Parameters (Google Analytics 4), map the Data Layer Variables or JavaScript Variables you created earlier to the corresponding Custom Dimension slots in Google Analytics.

    For example:

    • Custom Dimension 1: userId → Data Layer Variable userId
    • Custom Dimension 2: userType → Data Layer Variable userType
  3. Test the Tag:
    • Use Preview Mode in GTM to verify that the custom properties are sent correctly to Google Analytics.
    • Check in Google Analytics under Behavior > Events or Custom Dimensions (depending on your setup) to confirm that the custom user properties are being tracked.
  4. Publish the Changes: After confirming that everything works correctly, go ahead and Publish the changes in Google Tag Manager.

Step 4: Tracking Custom Properties in Other Platforms

If you’re sending custom user properties to other platforms like Facebook, Twitter, or LinkedIn, the process is similar:

  1. Create a tag for the respective platform (e.g., Facebook Pixel, Twitter Pixel).
  2. Map the custom properties to the platform’s event or tracking requirements.
  3. Use the appropriate variables you set up in GTM to send custom data.

For example, to send custom properties to Facebook Pixel, you would use the Facebook Pixel tag in GTM and include the custom properties as part of the Pixel event.

Step 5: Analyze Custom Properties

Once your custom properties are being tracked, you can analyze them in the respective platforms:

  • In Google Analytics, you can use Custom Dimensions to view user data in reports.
  • In Facebook or Twitter Ads, custom properties may help with better ad targeting or optimization.

Best Practices for Tracking Custom User Properties in GTM

  • Naming Conventions: Be consistent with naming your variables to avoid confusion (e.g., always use camelCase like userId, userType, membershipStatus).
  • Data Privacy: Ensure that the data you’re sending doesn’t violate privacy policies. Do not send personally identifiable information (PII) unless properly anonymized or compliant with regulations like GDPR.
  • Testing: Always test thoroughly in GTM’s Preview Mode to ensure that custom properties are captured correctly before publishing.

Conclusion

Tracking custom user properties in Google Tag Manager provides valuable insights into user behavior, helps improve segmentation, and enhances your ability to target specific audiences for marketing purposes. By pushing custom data to the Data Layer or using JavaScript variables, you can easily track properties such as user type, membership status, and other attributes and send them to platforms like Google Analytics, Facebook, or Twitter for better tracking and optimization.