Tag Manager Snippets to Collect User IDs and Add to Drift Widgets
In today’s marketing landscape, personalisation and seamless user experiences are key to building strong customer relationships. Drift, a powerful conversational marketing platform, allows businesses to engage with visitors in real-time through chat widgets. Enhancing these widgets with user identifiers like the Bizible Visitor ID, Google Analytics User ID, Google Analytics Session ID, and Mixpanel Device ID enables more personalized and context-aware conversations.
This blog post will explore how to use Google Tag Manager (GTM) to collect user IDs and integrate them with Drift widgets. We’ll cover the benefits of this approach, the technical steps involved, and best practices to ensure a successful implementation.
Why Collect User IDs for Drift Widgets?
User IDs serve as unique keys that help connect visitor behaviours across sessions and devices. By integrating these identifiers with Drift widgets, businesses can unlock several significant benefits:
- Improved Context for Conversations: Knowing a visitor’s journey on your website before initiating a conversation helps Drift bots or agents provide personalised responses. For instance, if a visitor has viewed your pricing page multiple times, the chatbot can offer to explain pricing plans.
- Better Attribution Across Touchpoints: Capturing user IDs ensures you can link Drift interactions to specific campaigns, helping attribute leads to their sources, whether it’s a paid ad, organic search, or referral.
- Enhanced Retargeting and Follow-Up: User IDs like Google Analytics User or Session IDs can be synced with other platforms, enabling precise retargeting and email follow-ups. For example, a visitor who engaged with a chatbot but didn’t convert can receive a retargeting ad with an exclusive offer.
- Data Consistency: Integrating Drift with user identifiers ensures that visitor data is consistent across your marketing and analytics platforms, creating a unified customer view.
- Improved Lead Qualification: By combining user behaviour data with Drift conversations, you can improve lead qualification and pass more meaningful insights to your sales team.
How It Works
Drift widgets allow custom data to be passed during a chat session, providing opportunities to personalise interactions and enhance tracking. Google Tag Manager (GTM) acts as the intermediary by capturing user IDs from cookies or other sources and pushing them into Drift’s widget properties.
In this case study, the cookie IDs to be captured include:
- Bizible Visitor ID
- Google Analytics User ID (_ga)
- Google Analytics Session ID (_ga_SESSION)
- Mixpanel Device ID
Step-by-Step Implementation Guide
1. Identify the User IDs to Capture
Determine which identifiers are most relevant to your Drift implementation. Here’s a breakdown of the IDs used in this case study:
- Bizible Visitor ID: Tracks multi-touch attribution.
- Google Analytics User ID (_ga): Links user sessions and devices.
- Google Analytics Session ID (_ga_SESSION): Represents session-level interactions.
- Mixpanel Device ID: Provides device-specific insights.
These IDs will form the foundation for personalising Drift conversations and tracking interactions.
2. Configure GTM Variables
To capture user IDs, you’ll need to extract them from browser cookies or other data sources. GTM variables are perfect for this task. Here’s how you can create them:
JavaScript Variable for Bizible Visitor ID(bizible_Visitor):
JavaScript Variable for Google Analytics User Id (ga_User):
JavaScript Variable for Google Analytics Session (ga_SESSION):
JavaScript Variable for Mixpanel device ID (mixpanel_device):
3. Create a Custom HTML Tag in GTM
To pass the Bizible Visitor ID (or other user IDs) to Drift widgets, we use a Custom HTML tag in GTM. Here’s the implementation for the Bizible Visitor ID:
This script ensures that the Bizible Visitor ID is retrieved from the GTM variable and passed to Drift’s api.setUserAttributes method once Drift is fully loaded. The drift.on(‘ready’) function ensures that the Drift widget is ready before attempting to set attributes.
You can replicate this approach for other identifiers (e.g., Google Analytics User ID, GA Session ID, Mixpanel Device ID) by updating the variable and attribute names accordingly.
4. Set the Trigger for Consent Management
For this implementation, we use a GTM trigger based on the driftInteraction event. This event ensures that the tag fires only when a Drift interaction is initiated. Using this approach helps integrate user attributes at the right moment, ensuring seamless personalisation while respecting user consent.
Steps to Configure the Trigger
- Go to the Triggers section in GTM and create a new trigger.
- Select Custom Event as the trigger type.
- In the Event Name field, enter driftInteraction.
- Add an optional condition to ensure that it only fires under specific circumstances, e.g.:
- Condition: {{CheckPerformanceCookieConsent}} equals 1 (if privacy compliance is required).
Assigning the Trigger
Attach the driftInteraction trigger to the “HTML – Drift User Attributes” tag created in Step 3. This ensures that the Bizible Visitor ID and other user attributes are passed to Drift widgets only when a relevant interaction occurs.
5. Debug and Test
Before deploying the setup, thoroughly test it to ensure accuracy:
- Use GTM’s Preview mode to confirm that the cookieDataUpdated event triggers the Drift tag.
- Verify in Drift’s admin interface that user attributes (e.g., bizible_visitor, ga_user) are being correctly populated during chat sessions.
- Test across different browsers and devices to ensure compatibility.
Best Practices for Implementation
- Respect User Privacy: Ensure your implementation aligns with GDPR and CCPA by leveraging consent management tools.
- Monitor Cookie Updates: Use events like cookieDataUpdated to dynamically handle consent changes.
- Document Configurations: Maintain documentation of GTM variables, tags, and triggers for easy troubleshooting and updates.
- Enhance Personalisation: Leverage Drift’s API to build more customised experiences using the captured user IDs.
Conclusion
This case study demonstrates how Google Tag Manager can be used to capture user IDs and integrate them with Drift widgets. By implementing this solution, businesses can provide more personalised chat experiences, improve campaign attribution, and ensure data consistency across platforms.
The approach outlined here is scalable and ensures compliance with privacy regulations, making it suitable for businesses looking to enhance their conversational marketing efforts. By combining tools like GTM, Drift, and analytics cookies, organisations can bridge the gap between visitor behaviours and real-time engagement, delivering meaningful interactions that drive results.
For tailored guidance or support with similar implementations, contact the Hive Digital Team today. We’re here to help you transform your marketing operations with data-driven strategies.