Flowboost Question

Anonymous
Not applicable

Flowboost Question

I have 10 url fields that need to have the http:// removed I was hoping to achieve this with flowboost and some regex "var url = url.replace(/(^\w+:|^)\/\//, '');"

My question is, can I make one webhook for all 10 fields or will I need to make one for each?

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Question

Hey Roger,

You can definitely do them all at once! And if you just want the hostname (www.example.com) without the protocol, you can use FBHttp.parseUrl (a built-in) shortcut instead of a regex:

var urls = {

    Website1 : FBHttp.parseUrl({{Lead.Website1}}).hostname,

    Website2 : FBHttp.parseUrl({{Lead.Website2}}).hostname,

    Website3 : FBHttp.parseUrl({{Lead.Website3}}).hostname

};

(Then set your response mappings for urls.Website1, urls.Website2, etc.)

Anonymous
Not applicable

Re: Flowboost Question

Would FBHttp return linktrack.info/.2sa0d from http://linktrack.info/.2sa0d?

Also would this be the right direction if they may be null?

Var urls = {

url1  : {{lead.twitter}},

url2  : {{lead.facebook}},

url3  : {{lead.instagram}},

url4  : {{lead.pinterest}},

url5  : {{lead.zillow}},

url6  : {{lead.realtor}},

url7  : {{lead.trulia}},

url8  : {{lead.craigslist}},

url9  : {{lead.landingpage}},

url10 : {{lead.youtube}}

}

For (var uri in url) {

if (urls[uri] !== null && urls[uri] !==''){

urls[uri] : FBHttp.parseUrl{urls[uri]}.hostname;

}

}

or would it be?

Var urls = {

twitter     : FBHttp.parseUrl{{{lead.twitter}}}.hostname,

facebook    : FBHttp.parseUrl{{{lead.facebook}}}.hostname,

instagram   : FBHttp.parseUrl{{{lead.instagram}}}.hostname,

pinterest   : FBHttp.parseUrl{{{lead.pinterest}}}.hostname,

zillow      : FBHttp.parseUrl{{{lead.zillow}}}.hostname,

realtor     : FBHttp.parseUrl{{{lead.realtor}}}.hostname,

trulia      : FBHttp.parseUrl{{{lead.trulia}}}.hostname,

craigslist  : FBHttp.parseUrl{{{lead.craigslist}}}.hostname,

landingpage : FBHttp.parseUrl{{{lead.landingpage}}}.hostname,

youtube     : FBHttp.parseUrl{{{lead.youtube}}}.hostname

}

SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Question

For that, you'd append the .path:

var urls = {

    Website1 : FBHttp.parseUrl({{Lead.Website1}}).hostname + FBHttp.parseUrl({{Lead.Website1}}).path,

    Website2 : FBHttp.parseUrl({{Lead.Website2}}).hostname + FBHttp.parseUrl({{Lead.Website2}}).path,

    Website3 : FBHttp.parseUrl({{Lead.Website3}}).hostname + FBHttp.parseUrl({{Lead.Website3}}).path

};   

Or you could do that much less repetitively with some looping, but this should get you going.

SanfordWhiteman
Level 10 - Community Moderator

Re: Flowboost Question

Also would this be the right direction if they may be null?

Marketo will send an empty string, not a JS/JSON null, so you don't have to worry about that.

To flexibly massage an unlimited list of URLs, I'd go like so (warning: is relatively advanced JS if you're not into map/reduce!):

var websiteFields = {

  Website1 : {{Lead.Website1}},

  Website2 : {{Lead.Website2}},

  Website3 : {{Lead.Website3}}

},

urlParts = ["hostname","path"], 

urls = Object.keys(websiteFields) 

.reduce( (acc, site) => { 

  acc[site] = urlParts.reduce( (acc, part) =>

    websiteFields[site] ? acc + FBHttp.parseUrl(websiteFields[site])[part] : ""

  ,"");

  return acc; 

},{});