Does your CRM, E-commerce or other tool combine first and last names into a single field?
Contact data comes in many different forms and at times the contact data you are hoping to use in Postalytics may have a combined first and last name. Postalytics requires that they be separated.
Fortunately, Zapier provides a tool that with a little JavaScript code and an additional step in your Zapier workflow, makes it easy to separate first and last names from a combined data field.
First, Create A Triggered Drip Campaign In Postalytics In “Test Mode”
Before you start, be sure to setup a Triggered Drip campaign in Postalytics that uses the Zapier integration. By default, the campaign will be in “Test Mode” to enable you to send test contacts through without actually sending mail. Double check to make sure your campaign is in Test Mode. Here’s an article that describes this in greater detail: Zapier Triggered Drip Test Mode
Following the steps below Postalytics will help you separate your combined first and last name. In this example we will be using Zapier to pull in contacts from Google Sheets.
- Sign into your Zapier account at https://zapier.com
- Click Make a Zap in the top right navigation
- Name your Zap in the top left of your screen
Google Sheets Setup
- Choose your App. Select Google Sheets
- Choose Trigger Event. Select New Spreadsheet Row
- Choose your account
- Choose your spreadsheet and worksheet and click continue
- Test a contact row is being pulled in correctly. If yes, click test and continue.
Code By Zapier Setup
Next, we’ll setup the Code By Zapier tool to run our JavaScript snippet:
- Click the + symbol below the Google Sheet app and search for “Code by Zapier”
- Add “Code by Zapier” and under Choose Action Event select Run JavaScript and click continue
- Under Input Data add “FullName” no spaces, special characters and exactly as spelled to the first box
- Under Input Data select the column that contains your combined name field
- Under Code (required) remove all text in the input and paste the following JavaScript then click continue
Add The Following JavaScript Into Code By Zapier
//ZAPIER BEGIN
//Set isNameReversed to true if the order of the full name is last name, first name else leave false let isNameReversed = false; let hasCompany = false;
output = {firstname: "", lastname: "", company: ""};
let fullName = inputData.FullName.trimLeft().trimRight(); let firstName = fullName.split(' ').slice(0, -1).join(' ').replace(',','').trimLeft().trimRight(); let lastName = fullName.split(' ').slice(-1).join(' ').replace(',','').trimLeft().trimRight();
if(firstName.length > 0 && lastName.length > 0) { if(!isNameReversed) { output['firstname'] = firstName; output['lastname'] = lastName; } else { output['firstname'] = lastName; output['lastname'] = firstName; } } else if(hasCompany) { output['company'] = firstName + lastName; } else { output['firstname'] = firstName + lastName; }
//ZAPIER END
Options with JavaScript Code
- If your combined name field has the first and last name in reverse order replace “false” to “true” where “let isNameReversed = false”
- If your combined name field also contain company names replace “false” to “true” where “let hasCompany = false”. This will help pass Postalytics requirements where a field contains either a single name with no white space or a single company name such as “Postalytics”.
Separate combined name continued
- Click continue and then click test & review. Confirm that the combined name have been separated into firstname and lastname. If the combined name is being separated correctly, click test & continue and begin mapping fields to Postalytics
Add The Postalytics Step To The Zap
- Search for Postalytics and select.
- Under Choose Action Event select “Send and Track a Postcard or Letter” and click continue
- Choose your Postalytics account and click continue. Sign in may be required.
- Choose your triggered drip campaign
- When mapping fields to Postalytics, under First Name select Run Javascript to firstname
- When mapping fields to Postalytics under Last Name select Run Javascript to lastname
- Your combined name field may also contains company names. If so, in the “Code by Zapier” JavaScript set hasCompany = false; to hasCompany = true; under company(optional) select Run JavaScript to company. review the Options with JavaScript Code above for more information
- Map the remaining address and personalization fields and when complete click continue.
- Review the test and confirm the data is being separated.
- If all is working correctly. Click Done Editing.
- Log into your Postalytics account, visit your campaign dashboard and click preview in the top right corner. A modal window will popup and shortly after will show the mail pieces created in test mode.
- Once confirmed everything is working as expected. Turn your Zap on and toggle your Postalytics Triggered Drip Campaign to Live Mode.
Your Zap Will Run Whenever Triggered
That’s it! Your Zap will automatically separate first and last names into the appropriate fields in Postalytics each time it is triggered.