Automate Attribution in Salesforce (using UTM data from Segment)


This recipe writes a contact property in Salesforce to include the UTM parameters that contact has attached to the sessions.


Recipe

Install and Configure Segment for Pageview Analytics Data

Segment is a data pipe for sending customer data from one tool to another set of tools. This includes sending on-page tracking data to other tools (including Hull).

To set this up, you need to install Segment in the page on your website (or mobile and server side options). To set this up for you, review Segment’s documentation here.

This will be your “Source”. Data captured here (including analytics events and page views) can be passed to other tools and services - including Hull.

To setup Hull as a destination, go to the Sources page in your Segment Workspace. Click on the source you have setup (e.g. Javascript, if you’ve installed Segment’s analytics.js script) - you’ll land on an overview page.

Choose “Integrations” from the top navigation. You’ll see a catalog of different tools you can send your analytics data to from Segment. Search for and click Hull.

Under “Settings” on the left hand side, you’ll need to paste your Hull API key. You can find your Hull API key within your Hull account.

Login to Hull, go to the Ships tab, and choose “Install Ship”. On the settings page, copy the Hull API key from the right hand side and paste it into the Hull integrations page on Segment. You can then add Hull as a destination from Segment.

In your Segment Ship settings in Hull, scroll down to enable “Handle Pages”. This will send all page view data to Hull from Segment.

Install the Processor

Hull processors allow you to transform data using javascript code to create custom properties and events from existing data. To install a new Processor, go to “Ships” and search for Processor. Click “Install” to add the processor.

Configure the Processor for Attribution

The Attribution Processor creates properties - “traits” - using UTM campaign parameters:

  • Source
  • Medium
  • Content
  • Campaign
  • Term

The properties can then be synced natively to other tools as a contact property.

In Ships, go to your blank Processor that you’ve installed. On the overview page, you’ll see three columns.

The left column is the data you can manipulate - the input. The central column is where you can add your JavaScript code The right column is the result - the output.

Copy and paste the following code into the central column to write attribution from all your UTM codes to your contacts


const UTM_KEYS = ['source', 'medium', 'content', 'campaign', 'term'];


// Lookup first session with UTM tags
const attribution = ['first', 'signup', 'latest'].reduce((attr, k) => {
  if (attr) return attr;

  const referrer = user[`${k}_session_initial_referrer`];
  const host = referrer && urijs(referrer).host();
  const utms = UTM_KEYS.reduce((ret, u) => {
    const val = user[`${k}_session_initial_utm_${u}`];
    if (!val) return ret;
    return Object.assign(ret, { [u]: val });
  }, {});

  const { source, medium, content, campaign, term } = utms;

  if (source || medium || campaign) {
    return utms;
  } else if (referrer) {
    // If cookie UTM_source exists
    // AND the referrer exists
    // Then utm_medium = referrer 
    // utm_source = domain of the referrer (google.com)

    // If the referrer is Google, Yahoo or Bing, 
    // aThen utm_medium = SEO and utm_source = Google, Yahoo or Bing
    const searchEngine = (host.match(/google|yahoo|bing/) || [])[0];

    if (searchEngine) {
      return { source: searchEngine, medium: 'SEO' }
    } else {
      return { source: host, medium: 'referrer' };
    }    
  }
}, null);

if (attribution) {
  traits(attribution, { source: 'attribution' })
}


Users will pass through this processor every time their properties are updated.

Install Salesforce connector

Salesforce CRM keeps all data on your leads and customers in one place. Hull allows you to manage what goes into your Salesforce contact records, including data from other tools and services.

To install Salesforce, go to the Ships page and click “Add Ship”. Search for Salesforcce and click “Install”. You’ll be prompted to login with your Salesforce credentials to connect your accounts.

Sync Contacts and Records to Salesforce

Once you’ve installed Salesforce, go to the Salesforce Ship page. Click on Settings. Here, you’ll be able to control who and what gets synced to Salesforce.

The first thing is to choose which segments gets synced to Salesforce. By default (when blank), every contact will be sent to Salesforce. This can make your Salesforce account less useful, and use up significant storage capacity (which they charge a lot for).

Instead, you may choose to sync only certain segments of contacts you’ve created in Hull like Demo Requested.

The second thing is to choose which contact properties will get sent and synced with Salesforce for both Contacts and Leads. You can choose whether Hull will overwrite existing values in Salesforce (otherwise Hull will populate only blank fields).

Finally, you can choose what values in Salesforce you want to sync back to Hull. These values can then be used in other tools.


Sources

Destinations


How can you implement this at your company?

Thanks , We'll be in touch!

Get in touch to organise your customized cookbook of Sales and Marketing automation recipes


Liked this recipe? Share it!