Getting started with clearbit.js

Clearbit.js makes it easy to send data from your website to Clearbit, enabling Clearbit reveal to identify the companies visiting your site in real time.

Screen_Shot_2018-10-03_at_2.40.47_PM.png

Add the following snippet to your website html

The first step is to copy and paste this snippet into the <head> element of your website:

<script>
  !function(){var clearbit=window.clearbit=window.clearbit||[];if(!clearbit.initialize)if(clearbit.invoked)window.console&&console.error&&console.error("Clearbit snippet included twice.");else{clearbit.invoked=!0;clearbit.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","page","once","off","on"];clearbit.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);clearbit.push(e);return clearbit}};for(var t=0;t<clearbit.methods.length;t++){var e=clearbit.methods[t];clearbit[e]=clearbit.factory(e)}clearbit.load=function(t){var e=document.createElement("script");e.async=!0;e.src=("https://js.clearbit.com/v1/"+t+"/clearbit.min.js");var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};clearbit.SNIPPET_VERSION="3.1.0";
  clearbit.load('CLEARBIT_PUBLISHABLE_KEY');
  clearbit.page();
  }}();
</script>

Don't forget to replace CLEARBIT_PUBLISHABLE_KEY with your Clearbit publishable key.

Note: You'll want to add this in addition to any existing Clearbit tags on you page currently. This will also drop a cookie to be used with user identification functionality below.

If you just want to Reveal your anonymous traffic, you're all done! Visit your Clearbit Reveal Accounts dashboard to see your live web traffic. If you want to be more precise about which known people are on your site at a given time (as opposed to just which companies), you can also identify your logged in users.

Identify your users

Identifying users allows clearbit.js to associate page view events with a specific user.

Screen_Shot_2018-10-03_at_2.40.18_PM.png

The way you identify a user looks like this:

clearbit.identify('USER_ID', {
  email: 'EMAIL_ADDRESS'
});

In addition to identifying your logged in users, you can also associate these users with their company by adding a company_domain attribute to the identify call. For example, if your user had an ID of GUID-1234-5678-9012 and an email address of alex@clearbit.com, you would make the following call:

clearbit.identify('USER_ID', {
  email: 'alex@clearbit.com',
  company_domain: 'clearbit.com'
});

Because this is going to be different for each and every user of your site, you'll need to replace the hard coded values above with the user ID, and email address of the currently logged in user. Depending on the templating language you use, it might look like this:

clearbit.identify('{{ user_id }}', {
  email: '{{ user_email }}',
company_domain: '{{domain}}'
});