@@ -21,7 +21,7 @@ var Klaviyo = (module.exports = integration('Klaviyo')
2121 . global ( '_learnq' )
2222 . option ( 'apiKey' , '' )
2323 . option ( 'enforceEmail' , false )
24- . tag ( '<script src="//a .klaviyo.com/media /js/analytics/analytics .js">' ) ) ;
24+ . tag ( '<script src="//static .klaviyo.com/onsite /js/klaviyo .js">' ) ) ;
2525
2626/**
2727 * Initialize.
@@ -58,23 +58,31 @@ Klaviyo.prototype.loaded = function() {
5858 */
5959
6060Klaviyo . prototype . identify = function ( identify ) {
61- // if you don't send either userId or email, noop
62- if ( ! identify . userId ( ) && ! identify . email ( ) ) return ;
6361 // TODO: should map/alias the rest of the reserved props
6462 var traitAliases = {
6563 email : '$email' ,
6664 id : '$id' ,
6765 firstName : '$first_name' ,
6866 lastName : '$last_name' ,
6967 phone : '$phone_number' ,
70- title : '$title'
68+ title : '$title' ,
69+ exchangeId : '$exchange_id'
7170 } ;
72- // don't add $id or id if email only option is enforced to prevent some edge case dupe profile issues with Klaviyo API
71+
7372 var traits = identify . traits ( traitAliases ) ;
73+
74+ // If there is not a user ID, email address, or an exchange ID, noop
75+ //
76+ // NOTE: An exchange ID is an encrypted identifier that Klaviyo
77+ // consumes server-side. It is considered a valid identifier.
78+ if ( ! identify . userId ( ) && ! identify . email ( ) && ! traits . $exchange_id ) return ;
79+
80+ // don't add $id or id if email only option is enforced to prevent some edge case dupe profile issues with Klaviyo API
7481 if ( this . options . enforceEmail ) {
7582 remove ( traits , 'id' ) ;
7683 remove ( traits , '$id' ) ;
7784 }
85+
7886 // if you enforce email but you don't send email, noop
7987 if ( this . options . enforceEmail && ! traits . $email ) return ;
8088 push ( 'identify' , traits ) ;
0 commit comments