Back

This guide shows how to add Tealium to Salesforce to track changes to "Lead" and "Contact" object types in the Universal Data Hub.

In this article:

Table of Contents Placeholder

Requirements

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 Universal Data Hub (UDH) 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 UDH to Salesforce

The Tealium for Salesforce solution can link records from the UDH into Salesforce by specifying a shared identifier attribute. In UDH 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 UDH attribute.

Additional reading: Salesforce Connector Setup Guide for AudienceStream

To add this custom field to the Lead object:

  1. From Setup, go to Lead > Fields.
  2. 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.

Lead Custom Field - Tealium ID

sfdc-tealium-id-custom-field.jpg

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:

  1. From the Developer Console create a new Class named "TealiumCollect".
  2. 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(tealiumConfig.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:

  1. Within the Developer Console, create a new Trigger named "TealiumLeadUpdate" (or "TealiumContactUpdate" based on the object).
  2. Copy and paste the code below.
  3. 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:

  1. Go to Lead > Fields.
  2. Click Map Fields.
  3. Click Contact.
  4. Map "tealium_id" in the Lead column to "Tealium ID" in the Contact column.
    tealium-salesforce-lead-conversion-mapping.png
  5. 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 Example

Screen Shot 2016-10-04 at 2.32.44 PM.png 

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:

  1. Go to Enrich > Attributes.
  2. Click + Add Attribute.
  3. Select the scope: Event
  4. Select the type: Universal Data Object
  5. Select the data type: String
  6. Set the Name to the same variable name used in the trigger code eg. "crm_lead_status".
  7. Save/Publish.