The nativeFunctions.klaviyoMergeProfiles()
function allows you to merge user profiles across mobile app and website platforms in Klaviyo. This function should only be called in Canvas-based environments.
// Check if the user agent contains 'canvas' (case-insensitive)
if (navigator.userAgent.toLowerCase().includes('canvas')) {
try {
// Merge profile using external ID
nativeFunctions.klaviyoMergeProfiles('user123', null)
} catch (error) {
// Handle any potential errors
console.error('Profile merge failed:', error)
}
}
// Check if the user agent contains 'canvas' (case-insensitive)
if (navigator.userAgent.toLowerCase().includes('canvas')) {
try {
// Merge profile using email
nativeFunctions.klaviyoMergeProfiles(null, 'user@example.com')
} catch (error) {
// Handle any potential errors
console.error('Profile merge failed:', error)
}
}
The klaviyoMergeProfiles()
function performs an internal check to determine the user's existence in Klaviyo before initiating the merge process. This means:
After a successful profile merge, the app automatically updates the external user ID in the userInfo
object. This process ensures:
More details can be found here: https://www.mobiloud.com/docs/get-user-information
nativeFunctions.klaviyoMergeProfiles(externalID, email)
externalID
(Optional): A unique identifier for the useremail
(Optional): The user's email addressexternalID
and email
simultaneouslynativeFunctions.klaviyoMergeProfiles()
in a user agent checktoLowerCase()
to ensure case-insensitive matching