- TLC Home Home
- Discussions & Ideas Discussions & Ideas
- Product Guides Product Guides
- Knowledge Base Knowledge Base
- Developer Docs Developer Docs
- Education Education
- Blog TLC Blog
- Support Desk Support Desk
This guide shows how to add Tealium to Salesforce to track changes to "Lead" and "Contact" object types in the Customer Data Hub.
In this article:
The Tealium for Salesforce solution is installed as a number of Apex classes: one for the Tealium Collect service and one or more to trigger on object updates. It also requires updates to Salesforce configuration to support linking records from Customer Data Hub and to allow the sending of HTTP requests from Salesforce to Tealium.
For a video overview of this solution, check out this challenger video:
The Tealium for Salesforce solution can link records from the Customer Data Hub into Salesforce by specifying a shared identifier attribute. In Customer Data Hub this attribute can be any Visitor ID attribute that uniquely identifies records coming from an ingestion sync (such as Omnichannel uploads). In Salesforce you must create a custom field in the Object named "Tealium ID" to capture that Customer Data Hub attribute.
Additional reading: Salesforce Connector Setup Guide for AudienceStream
To add this custom field to the Lead object:
tealium_id_teal
The _teal
suffix helps namespace these variables to Tealium.
This TealiumCollect Apex class generates the HTTP request to the Tealium Collect service. It takes the Tealium configuration and data layer values and formats them into the required URL format.
Additional reference: Apex Quick Start
To add the TealiumCollect Apex class:
public class TealiumCollect { private static Boolean debug = true;
/* TEALIUM CONFIGURATION */
private static String tealiumAccount = 'YOUR_ACCOUNT';
private static String tealiumProfile = 'YOUR_PROFILE';
private static String tealiumDataSourceKey = 'YOUR_DATASOURCE_KEY';
private static String tealiumEventType = 'derived';
private static String tealiumEndpoint = 'https://collect.tealiumiq.com/event';
@future(callout=true)
public static void track(Map<String, String> tealiumData){ List<String> tealiumParams = New List<String>(); tealiumParams.add('tealium_account' + '=' + tealiumAccount); tealiumParams.add('tealium_profile' + '=' + tealiumProfile); tealiumParams.add('tealium_datasource' + '=' + tealiumDataSourceKey); tealiumParams.add('tealium_event_type' + '=' + tealiumEventType); tealiumParams.add('tealium_event' + '=' +
EncodingUtil.urlEncode(tealiumData.get('tealium_event'), 'UTF-8'));
String tealiumVid = tealiumData.get('tealium_vid'); if(tealiumVid == null || tealiumVid == ''){ tealiumData.remove('tealium_vid'); } for(String key : tealiumData.keySet()){ try{ String value = tealiumData.get(key); Boolean valueTest = (value != null); tealiumParams.add(key + '=' + (valueTest ? EncodingUtil.urlEncode(value, 'UTF-8') : '')); }catch(Exception e){} } HttpRequest req = new HttpRequest(); String tealCollect = tealiumEndpoint + '?' + String.join(tealiumParams, '&');
req.setEndpoint(tealCollect);
if(debug){
System.debug(tealCollect);
} req.setMethod('GET'); Http http = new Http(); HTTPResponse res = http.send(req); } }
This trigger activates based on an update to a Salesforce object. Triggers can be changed to activate on many other object stages and can be customized and filtered to specific scenarios.
Additional reference: Apex - Triggers
Use the following steps to create the Tealium trigger:
trigger tealiumContactUpdate on Contact (after insert, after update) { String tealiumEvent = 'crm_contact_update';
/* POPULATE TEALIUM DATA LAYER */
Map<string,string> tealiumData = new Map<string,string>();
for (Contact sfdcObj : Trigger.new ){ /* REQUIRED TEALIUM DATA */ tealiumData.put('tealium_event', tealiumEvent);
tealiumData.put('tealium_vid', sfdcObj.tealium_id_teal__c);
/* SFDC DATA */
tealiumData.put('customer_email', sfdcObj.Email);
tealiumData.put('crm_lead_source', sfdcObj.LeadSource); tealiumData.put('has_opted_out_email', String.valueOf(sfdcObj.HasOptedOutOfEmail));
tealiumData.put('has_opted_out_phone', String.valueOf(sfdcObj.DoNotCall));
tealiumData.put('mobile_phone_number', String.valueOf(sfdcObj.MobilePhone));
tealiumData.put('home_phone_number', String.valueOf(sfdcObj.Phone));
tealiumData.put('customer_first_name', sfdcObj.FirstName); tealiumData.put('customer_last_name', sfdcObj.LastName);
tealiumData.put('customer_title', sfdcObj.Title);
tealiumData.put('crm_account', String.valueOf(sfdcObj.Account));
/* Addition Custom Fields */
/* tealiumData.put('custom_field', sfdcObj.customField); */ TealiumCollect.track(tealiumData); }
}
trigger tealiumLeadUpdate on Lead (after insert, after update) { String tealiumEvent = 'crm_lead_update';
/* POPULATE TEALIUM DATA LAYER */
Map<string,string> tealiumData = new Map<string,string>();
for (Lead sfdcObj : Trigger.new ){ /* REQUIRED TEALIUM DATA */ tealiumData.put('tealium_event', tealiumEvent);
tealiumData.put('tealium_vid', sfdcObj.tealium_id_teal__c);
/* SFDC DATA */
tealiumData.put('customer_email', sfdcObj.Email);
tealiumData.put('crm_lead_status', sfdcObj.Status);
tealiumData.put('crm_lead_source', sfdcObj.LeadSource);
tealiumData.put('crm_lead_rating', sfdcObj.Rating);
tealiumData.put('crm_lead_industry', sfdcObj.Industry);
tealiumData.put('crm_lead_company', sfdcObj.Company);
tealiumData.put('has_opted_out_email', String.valueOf(sfdcObj.HasOptedOutOfEmail));
tealiumData.put('has_opted_out_phone', String.valueOf(sfdcObj.DoNotCall));
tealiumData.put('mobile_phone_number', String.valueOf(sfdcObj.MobilePhone));
tealiumData.put('home_phone_number', String.valueOf(sfdcObj.Phone));
tealiumData.put('customer_first_name', sfdcObj.FirstName);
tealiumData.put('customer_last_name', sfdcObj.LastName);
/* Addition Custom Fields */
/* tealiumData.put('custom_field', sfdcObj.customField); */ TealiumCollect.track(tealiumData); } }
In order to preserve the custom field "Tealium ID" during a Lead conversion to a Contact you must map "Lead.Tealium ID" to "Contact.Tealium ID".
Additional reference: Salesforce - Map Custom Lead Fields for Lead Conversion
Use the following steps to create a custom field mapping:
tealium_id
in the Lead column to Tealium ID"in the Contact column.The Tealium Collect endpoint must be registered in the Remote Site Settings of Salesforce in order to send HTTP requests.
Additional reference: Apex - Adding Remote Site Settings
Create the new remote site with the following settings:
The Salesforce variables used in the Apex trigger code must be defined in Tealium as Event Attributes. You can see what data is coming from Salesforce by inspecting the trigger code or by using Live Events to see the data in real-time.
Use the following steps to add Event Attributes:
crm_lead_status
.Copyright All Rights Reserved © 2008-2021