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:
Table of Contents Placeholder
Requirements
Salesforce administrator access
Tealium account enabled for AudienceStream, DataAccess, or EventStream
Installation
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:
Linking Records from Customer Data Hub to Salesforce
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:
From Setup, go to Lead > Fields.
Add a new custom field of type 'Text' with the following settings:
Field Label: Tealium ID
Length: 100
Field Name: tealium_id_teal
The _teal suffix helps namespace these variables to Tealium.
Click Save.
Apex Class: TealiumCollect
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:
From the Developer Console create a new Class named "TealiumCollect".
Copy and paste the following code, making sure to specify your account, profile, and data source key:
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);
}
}
Apex Trigger: Lead/Contact Update
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:
Within the Developer Console, create a new Trigger named "TealiumLeadUpdate" (or "TealiumContactUpdate" based on the object).
Copy and paste the code below.
Modify the code to match the object you are tracking (Contact or Lead).
Contact Object 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);
} }
Lead Object Trigger
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);
}
}
Lead Conversion Mapping
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:
Go to Lead > Fields.
Click Map Fields.
Click Contact.
Map tealium_id in the Lead column to Tealium ID"in the Contact column.
Click Save.
Enable Remote Site
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:
Remote Site Name: TealiumCollect
Remote Site URL: https://collect.tealiumiq.com
Disable Protocol Security: Enable
Remote Site Example
Add Salesforce Event Attributes
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:
Go to Enrich > Attributes.
Click + Add Attribute.
Select the scope: Event
Select the type: Universal Data Object
Select the data type: String
Set the Name to the same variable name used in the trigger code, such as crm_lead_status .
Save/Publish.
... View more