Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Added support for sending first and last names #13

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.4.0 / 2018-07-07
==================

* Added support for sending first and last names

2.3.0 / 2017-08-23
==================

Expand Down
29 changes: 27 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,28 @@ Elevio.prototype.loaded = function() {
*/

Elevio.prototype.identify = function(identify) {
var integrationSettings = identify.options(this.name);
var name = identify.name();
var email = identify.email();
var plan = identify.proxy('traits.plan');
var traits = identify.traits();
var user_hash;
var firstName;
var lastName;

// Check for firstName property
// else check for name
if (traits.firstName) {
firstName = traits.firstName;
lastName = traits.lastName;
} else if (traits.name) {
var nameArray = traits.name.split(' ') || [];
firstName = nameArray.shift();
lastName = nameArray.pop();
}

if (integrationSettings.userHash) user_hash = integrationSettings.userHash;
if (integrationSettings.user_hash) user_hash = integrationSettings.user_hash;

var removeTraits = ['id', 'name', 'firstName', 'lastName', 'email'];

Expand All @@ -63,11 +81,18 @@ Elevio.prototype.identify = function(identify) {
user.via = 'segment';
if (email) user.email = email;
if (name) user.name = name;
if (firstName) user.first_name = firstName;
if (lastName) user.last_name = lastName;
if (plan) user.plan = [plan];
if (user_hash) user.user_hash = user_hash;
if (plan) user.groups = [plan];
if (objectKeys(traits).length > 0) user.traits = traits;
window._elev.user = user;
if (typeof window._elev.setUser === 'function') {

if (typeof window._elev.on === 'function') {
// Customer loading v4
window._elev.setUser(user);
} else {
// Customer loading v3 (deprecated)
window._elev.user = user;
}
};
Loading