Personalize Webpage based on Clearbit DataUpdated 30/04/2019


This snippet is used in the Hull-browser connector, and updates the current page whenever any update to User and account data is received for a select number of clearbit attributes.


//We know lodash is in the page.

var t = $(".header__title").text();
var companyDomain = account.domain || account["clearbit/domain"]
var companyName = account["clearbit/name"];
var companyLogo = account["clearbit/logo"];
var pageLoad = changes === undefined;

var companyDomainChanged = false;
var companyLogoChanged = false;
var companyNameChanged = false;

if (changes && changes.account) {
  var companyDomainChanged = !!changes.account["clearbit/domain"] || !!changes.account.domain;
  var companyLogoChanged = !!changes.account["clearbit/logo"];
  var companyNameChanged = !!changes.account["clearbit/name"];
}

//Personalize Feature pages text
if (companyName && (companyNameChanged || pageLoad)) {
  if (window.location.href.indexOf('/features/')>-1) {
    $(".header__title").text(t.replace(/Try Hull\s*$/, "Try Hull at "+companyName))
  }
  $('.window-header .header-name').text(companyName);


  drift.on("ready", function(api) {
    const identify = _.assign({},
      _.pick(user, ["email", "domain", "name"]),
      user.traits,
      _.reduce(account || {}, (m, v, k) => { m["account_"+k.replace("/","_")] = v; return m;}, {})
    );
    drift.identify(user.id, identify);

    if (companyName) {
      api.showWelcomeMessage({
        message: "How can we help "+companyName+" today ?",
        avatarUrl: companyLogo
      });
    }
  });

}

//Personalize Homepage logo
if (companyLogo && (companyLogoChanged || pageLoad)) {
  $(".profile-window-container .header-icon img")
    .attr('src', companyLogo+"?s=128")
    .css({"border-radius": "100px"})
}

//Personalize homepage emails
if(companyDomain && (companyDomainChanged || pageLoad)){
  const email = $(".window-content .section-value").first().find("span");
  email.text(email.replace(/@.*$/,"@"+companyDomain));
}