5 min read

How to Integrate Clearbit Reveal with Google Analytics via Segment

Clearbit Reveal turns your anonymous traffic into full company profiles. For B2B companies, this data is super helpful! You can do things like:

  • Gauge whether you’re driving the right businesses to your site (enterprise vs. SMB, financial vs. healthcare or whatever)
  • Measure goal conversion rates by company size, industry, etc.
  • Send alerts for sales when target (or “named”) accounts hit your site
  • Create audiences for remarketing based on company name, size, industry, etc.

You can use the Reveal API to perform lookups and integrate the results into your apps or whatever, but the most straightforward use case is to use Clearbit Reveal Google Analytics to enrich your web traffic data.

If you use Segment to deploy your Google Analytics tracking code, Clearbit has a setup guide here.

That guide gave me a few issues, so I wrote this short-ish addendum to help you overcome any hurdles.

Create your Clearbit account

Head over to clearbit.com and create an account. Once you’re logged in, on the left sidebar, click “Get Started.” Scroll to the bottom and click “Reveal” (or just follow this link).

Now here’s where things can be a bit confusing. You’ll see an integration for Segment. That’s not what you want.

The Segment integration is for enriching events that flow through Segment on their way to the destinations (or warehouses) you have set up there. You want to pick Google Analytics (or follow this link to their setup tool).

Clearbit GA Integration

Setup your Custom Dimensions

If you’ve never setup Custom Dimensions in your GA account, you should be able to use their setup tool without a problem. It’ll auto-insert the Custom Dimensions in GA and spit out the exact JavaScript snippet you need to add to your sites.

All of my Custom Dimensions were previously used, so the tool blew up for me with the message badRequest: Error creating this entity. You have reached the maximum allowed entities of this type.

(Note: if you have the pro version of Google Analytics you shouldn’t run into this problem because you don’t have the 20 dimension limit. Also, congrats on being able to afford $150,000/year for one analytics tool. 🤑)

I figured the tool would ask me if I want to rename/overwrite my dimensions, but it didn’t (maybe GA’s API doesn’t allow PUT/PATCH?).

On failure, head on over to GA to manually create (or, more likely, rename) your Custom Dimensions. Give them a scope of “User” and follow Clearbit’s suggested naming conventions:

  • Clearbit Company Name
  • Clearbit Employees Range
  • Clearbit Industry Tags
  • Clearbit Tech Stack
  • Clearbit SubIndustry
  • Clearbit Industry
  • Clearbit Industry Group
  • Clearbit Sector
  • Clearbit Company Type
  • Clearbit Domain

It doesn’t matter which dimension you map these to as long as you make your JavaScript snippet match.

Custom Dimensions

Once you have all the dimensions you want in GA, manually modify Clearbit’s default JavaScript snippet and make it match your Custom Dimensions.

Here’s the default snippet from the setup guide:

<script>
  analytics.ready(function(){
    ga('require', 'Clearbit', {
      mapping: {
        companyName:           'dimension1',
        companyEmployeesRange: 'dimension2',
        companyTags:           'dimension3',
        companyTech:           'dimension4',
        companySubIndustry:    'dimension5',
        companyIndustry:       'dimension6',
        companyIndustryGroup:  'dimension7',
        companySector:         'dimension8',
        companyType:           'dimension9',
        companyDomain:         'dimension10'
      }
    });
  });
</script>

<script async src="https://ga.clearbit.com/v1/ga.js?authorization=pk_YOUR_KEY"></script>

Take note of the analytics.ready line — that’s needed to ensure that Clearbit waits until Segment has actually loaded GA onto the page before interacting with it. If you’re getting a ga is not defined error in your Chrome console, you’re likely missing the analytics.ready call.

Here’s the problem: the default snippet doesn’t contain all of the dimensions I want. Where’s Global Alexa Rank? What about Country?

I added these dimensions to Google Analytics, but they need to be in my snippet. I know which dimension numbers to map them to (I just need to look in GA), but what about Clearbit’s mapping names?

Is Clearbit Global Alexa Rank supposed to be “companyGlobaAlexaRank”? Or maybe it has to be “companyAlexaRank”? If you guess wrong, it won’t work.

Luckily, I was able to find the source of truth by looking at Clearbit’s ga.js source code:

Clearbit.prototype.setDimensions = function(company) {
  var ref, ref1;
  this.set(this.mapping.companyName, company.name);
  this.set(this.mapping.companyDomain, company.domain);
  this.set(this.mapping.companyType, company.type);
  this.set(this.mapping.companyTags, (ref = company.tags) != null ? ref.join(',') : void 0);
  this.set(this.mapping.companyTech, (ref1 = company.tech) != null ? ref1.join(',') : void 0);
  this.set(this.mapping.companySector, company.category.sector);
  this.set(this.mapping.companyIndustryGroup, company.category.industryGroup);
  this.set(this.mapping.companyIndustry, company.category.industry);
  this.set(this.mapping.companySubIndustry, company.category.subIndustry);
  this.set(this.mapping.companyCountry, company.geo.countryCode);
  this.set(this.mapping.companyState, company.geo.stateCode);
  this.set(this.mapping.companyCity, company.geo.city);
  this.set(this.mapping.companyFunding, company.metrics.raised);
  this.set(this.mapping.companyEmployeesRange, company.metrics.employeesRange);
  this.set(this.mapping.companyEmployees, company.metrics.employees);
  return this.set(this.mapping.companyAlexaRank, company.metrics.alexaGlobalRank);
};

The above function shows me what Clearbit expects each mapping name to be.

Clearbit should consider adding them all to the default snippet and let people remove the ones they don’t want.

Installing with Segment? Next to Segment?

As Segment users we don’t install JavaScript snippets. HA! That’s for mere mortals! Segment is “the last integration you’ll ever do”, remember?

You can imagine my shock when I read the setup guide and it told me to “insert the below script underneath the Segment JavaScript snippet.”

How dare you?

Well, turns out you DO have to integrate the Cleabit Reveal Google Analytics snippet manually outside of Segment. You will find a Clearbit destination in Segment, which might be tempting to activate, but it’s not for this. Again, that’s for enrichment.

So your last and final step should be to manually insert the Clearbit JavaScript snippet beneath your Segment snippet like so:

<!-- Start Segment -->
<script>
  // SEGMENT CODE LIVES HERE
</script>
<!-- End Segment -->

<!-- Start Clearbit -->
<script>
  analytics.ready(function() {
    ga('require', 'Clearbit', {
      mapping: {
        companyName:              'dimension1',
        companyDomain:            'dimension2',
        companyTags:              'dimension3',
        companySector:            'dimension4',
        companyIndustryGroup:     'dimension5',
        companyIndustry:          'dimension6',
        companySubIndustry:       'dimension7',
        companyType:              'dimension8',
        companyEmployeesRange:    'dimension9',
        companyAlexaRank:         'dimension10',
        companyCity:              'dimension11',
        companyState:             'dimension12',
        companyCountry:           'dimension13',
        companyFunding:           'dimension14',
        companyRevenue:           'dimension15',
        companyTech:              'dimension16'
      }
    });
  });
</script>

<script async src="https://ga.clearbit.com/v1/ga.js?authorization=YOUR_PK"></script>
<!-- End Clearbit -->

Hope this helps clear things up (ha ha!).