klaviyo-react-native-sdk
Version:
Official Klaviyo React Native SDK
111 lines (109 loc) • 3.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "EventName", {
enumerable: true,
get: function () {
return _Event.EventName;
}
});
exports.Klaviyo = void 0;
Object.defineProperty(exports, "ProfileProperty", {
enumerable: true,
get: function () {
return _Profile.ProfileProperty;
}
});
var _KlaviyoReactNativeSdk = require("./KlaviyoReactNativeSdk.js");
var _Profile = require("./Profile.js");
var _Event = require("./Event.js");
/**
* Implementation of the {@link KlaviyoInterface}
*/
const Klaviyo = exports.Klaviyo = {
initialize(apiKey) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.initialize(apiKey);
},
setProfile(profile) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.setProfile((0, _Profile.formatProfile)(profile));
},
setExternalId(externalId) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.setExternalId(externalId);
},
getExternalId(callback) {
return _KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.getExternalId(callback);
},
setEmail(email) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.setEmail(email);
},
getEmail(callback) {
return _KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.getEmail(callback);
},
setPhoneNumber(phoneNumber) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.setPhoneNumber(phoneNumber);
},
getPhoneNumber(callback) {
return _KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.getPhoneNumber(callback);
},
setProfileAttribute(propertyKey, value) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.setProfileAttribute(propertyKey, value);
},
setBadgeCount(count) {
// checking if method exists since this is iOS only and don't want a
// runtime error on android
if (_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.setBadgeCount) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.setBadgeCount(count);
} else {
console.log('setBadgeCount is not available on this platform');
}
},
resetProfile() {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.resetProfile();
},
setPushToken(token) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.setPushToken(token);
},
getPushToken(callback) {
return _KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.getPushToken(callback);
},
createEvent(event) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.createEvent(event);
},
registerForInAppForms(configuration) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.registerForInAppForms(configuration);
},
unregisterFromInAppForms: () => {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.unregisterFromInAppForms();
},
registerGeofencing() {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.registerGeofencing();
},
unregisterGeofencing() {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.unregisterGeofencing();
},
getCurrentGeofences(callback) {
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.getCurrentGeofences(callback);
},
/**
* Resolves a Klaviyo tracking link to a Universal Link URL,
* then handles navigation to the resolved URL.
* @param urlStr - The tracking link to be handled
*/
handleUniversalTrackingLink(urlStr) {
if (!urlStr || urlStr.trim() === '') {
console.error('[Klaviyo] Error: Empty tracking link provided');
return false;
}
// Validate that the URL is a Klaviyo universal tracking link using regex
// Pattern: https://domain/u/path
const klaviyoTrackingLinkPattern = /^https:\/\/[^/]+\/u\/.*$/;
if (!klaviyoTrackingLinkPattern.test(urlStr)) {
console.warn('[Klaviyo] Warning: Not a Klaviyo tracking link');
return false;
}
_KlaviyoReactNativeSdk.KlaviyoReactNativeSdk.handleUniversalTrackingLink(urlStr);
return true;
}
};
//# sourceMappingURL=index.js.map