Prepare a CSV file to import user data

When importing user data with a CSV upload, you will need to include certain fields as columns in the CSV file you upload. Depending on the type of data you want to import, the format of the column may look different.

For more on how to format your CSV file based on the type of data you want to import, click on what you would like to import below:

🚧

Check the file encoding

Before uploading, it is best practice to check the file's encoding to ensure it is encoded properly Check to see if it has Byte Order Mark and if it does you will need to encode simply as "UTF-8".

To check the encoding, you can open the file in Sublime Text and click in the menu File > Save with Encoding > "UTF-8" (not "UTF-8 with BOM").

User Attributes

When uploading new users and/or user attributes, it required your CSV include the user ID in the first column. Any attributes you want to upload will be in the following columns. You are also able to include the user's created date (unix) and lastActive time.

FieldData typeRequired?Description
userIdStringYESThe user ID. It must be the first column of the CSV file.
userAttributes.StringNOThe name of the user attribute.
Example: userAttributes.facebook_id
We highly recommend validating the data here, for example, if it's an email.
createdUnix timestampNOUse this to set the date and time the user was created. The value has to be in Unix time.
This will allow you to target users based on "time of first run," etc.
lastActiveUnix timestampNOUse this to set the date and time the user was last active. The value has to be in Unix time.
This will allow you to target users based on "last active," etc.

Uploading an Email attribute

If you have activated email with Leanplum, you will need to upload the email addresses for all your users. When uploading your csv file, make sure your users' email addresses are included as an attribute in the CSV file. Otherwise, Leanplum will not be able to email these users.

Example file format:

userIduserAttributes.ageuserAttributes.emailuserAttributes.interestscreatedlastActive
sample_user24[email protected]"[Sports,Finance]"14962752001580496000

The above sample file will create a user profile like this:

1376

Click to enlarge

📘

Email Attribute

When uploading the email attribute, make sure the name of the attribute matches the attribute name you have set in your email settings. This attribute will be used to store the email address and used to send the email.

For more on this visit our email setup doc

Device attributes

To upload device-level attributes, you can do so by including all the below fields when uploading. When you are uploading the file, you must include the user ID if there is one and the device ID so we can properly capture under the user.

🚧

Use the right API action

When importing device attributes, you must set the defaultAction to setDeviceAttributes in the API call.

FieldData typeRequired?Description
userIdStringYESThe user id. It must be the first column of the CSV file.
deviceIdStringYESThe device id. A single user may have multiple device ids.
iosPushTokenStringNOUse this to set the iOS push token of the device. Push tokens are device specific, so in the CSV file, you must specify which deviceId this token belongs to. This is done by having the device ID and the push token on the same row.
systemNameStringNoThe value should be either iOS or Android OS. This must match the push token type you are uploading.
gcmRegistrationIdStringNOUse this to set the Android push token of the device. Push tokens are device specific, so in the CSV file you must specify which deviceId this token belongs to. This is done by having the deviceId and the push token on the same row.

Example file format:

userIddeviceIdsystemNameiosPushTokengcmRegistrationIdbackground
sample_user1ABC-123iOS1234567TRUE
sample_user2ABC-456Android OS7654321TRUE

Events

When formatting your CSV for event uploads, you can import information on the number of occurrences of an event, the value of an event, the time an event first occurred, and more.

🚧

Use the right API action

When importing historical events, you must set the defaultAction to setUserAttributes in the API call.

FieldData typeRequired?Description
userIdStringYESThe user ID. It must be the first column of the CSV file.
events.eventName.countIntegerNONew lifetime count of for the current user.

Always set when doing historical uploads (meaning when users have no recorded occurrences of the event yet in Leanplum)
events.eventName.firstTimeUnix TimestampNOTime that the event first occurred, in seconds since midnight UTC on January 1, 1970.
events.eventName.lastTimeUnix TimestampNOTime that the event last occurred, in seconds since midnight UTC on January 1, 1970.
events.eventName.countIncrementIntegerNOAmount to increment the lifetime count of eventName.
events.eventName.valuenumber(float)NONew lifetime value of for the current user.
events.eventName.valueIncrementnumber(float)NOAmount to increment the lifetime value of eventName.

Example file format:

userIdevents.Purchase.firstTimeevents.Purchase.lastTimeevents.Purchase.countevents.Purchase.value
sample_user14962752001580496000320

This sample creates a profile like this:

1428

Click to enlarge

Now you can segment users based on the number of occurrences of the event in the Users page. For example:

2200

From the Users page, select Add Segment > Behavioral > Occurrences of event or state to set up this segment, then edit the values for you event and the number of occurrences.

Email unsubscribe / resubscribe

Use the information below to create a CSV that unsubscribes or subscribes a list of users for email.

Managing subscribing/unsubscribing for the Email channel:

FieldData typeRequired?Description
userIdStringYESThe user ID. It must be the first column of the CSV file.
unsubscribeChannelsToAddStringNOSet to "Email" to unsubscribe users from all marketing emails.
unsubscribeChannelsToRemoveStringNOSet to "Email" to resubscribe users from all marketing emails.

Example file format:

userIdunsubscribeChannelsToAddunsubscribeChannelsToRemove
sample_user1Email
sample_user2Email

Managing subscribing/unsubscribing for Email Categories:

FieldData typeRequired?Description
userIdStringYESThe user ID. It must be the first column of the CSV file.
unsubscribeCategoriesToAddString/ListNOSet to the IDs of the categories you wish to unsubscribe users from.
unsubscribeCategoriesToRemoveString/ListNOSet to the IDs of the categories you wish to subscribe users to.

Example file format:

userIdunsubscribeCategoriesToAddunsubscribeCategoriesToRemove
sample_user12
sample_user2["5""6""7""8"]
sample_user3["1""6""7""13"]["2""3""4""5"]