UNPKG

cordova-plugin-swrve

Version:

Android and iOS Cordova plugin for Swrve.

252 lines (202 loc) 8.92 kB
function SwrvePlugin() {} SwrvePlugin.prototype.android = false; SwrvePlugin.prototype.ios = true; // name is a string // payload is a JSON object SwrvePlugin.prototype.event = function(name, payload, success, fail) { if (payload == undefined || !payload || payload.length < 1) { return cordova.exec(success, fail, 'SwrvePlugin', 'event', [ name ]); } else { return cordova.exec(success, fail, 'SwrvePlugin', 'event', [ name, payload ]); } }; // attributes is a JSON object SwrvePlugin.prototype.userUpdate = function(attributes, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'userUpdate', [ attributes ]); }; // name is a string // date is a date SwrvePlugin.prototype.userUpdateDate = function(name, date, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'userUpdateDate', [ name, date ]); }; // currency is a string // quantity is an int SwrvePlugin.prototype.currencyGiven = function(currency, quantity, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'currencyGiven', [ currency, quantity ]); }; // itemName is a string // currency is a string // quantity is an int // cost is a int SwrvePlugin.prototype.purchase = function(itemName, currency, quantity, cost, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'purchase', [ itemName, currency, quantity, cost ]); }; // localCost is a double // localCurrency is a string // productId is a string // quantity is an int SwrvePlugin.prototype.unvalidatedIap = function(localCost, localCurrency, productId, quantity, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'unvalidatedIap', [ localCost, localCurrency, productId, quantity ]); }; // localCost is a double // localCurrency is a string // productId is a string // quantity is an int // reward is a JSONString SwrvePlugin.prototype.unvalidatedIapWithReward = function( localCost, localCurrency, productId, quantity, reward, success, fail ) { return cordova.exec(success, fail, 'SwrvePlugin', 'unvalidatedIap', [ localCost, localCurrency, productId, quantity, reward ]); }; SwrvePlugin.prototype.sendEvents = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'sendEvents', []); }; SwrvePlugin.prototype.getUserResources = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'getUserResources', []); }; SwrvePlugin.prototype.getUserResourcesDiff = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'getUserResourcesDiff', []); }; SwrvePlugin.prototype.refreshCampaignsAndResources = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'refreshCampaignsAndResources', []); }; SwrvePlugin.prototype.getMessageCenterCampaigns = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'getMessageCenterCampaigns', []); }; // identifier is an int SwrvePlugin.prototype.showMessageCenterCampaign = function(identifier, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'showMessageCenterCampaign', [ identifier ]); }; // identifier is an int SwrvePlugin.prototype.removeMessageCenterCampaign = function(identifier, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'removeMessageCenterCampaign', [ identifier ]); }; // identifier is an int SwrvePlugin.prototype.markMessageCenterCampaignAsSeen = function(identifier, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'markMessageCenterCampaignAsSeen', [ identifier ]); }; // campaignId is an int SwrvePlugin.prototype.embeddedMessageWasShownToUser = function(campaignId, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'embeddedMessageWasShownToUser', [ campaignId ]); }; // campaignId is an int, button is a string SwrvePlugin.prototype.embeddedMessageButtonWasPressed = function(campaignId, buttonId, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'embeddedMessageButtonWasPressed', [ campaignId, buttonId]); }; // campaignId is an int, personalizationProperties is a dictionary SwrvePlugin.prototype.getPersonalizedEmbeddedMessageData = function(campaignId, personalizationProperties, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'getPersonalizedEmbeddedMessageData', [ campaignId, personalizationProperties]); }; // campaignId is an string, personalizationProperties is a dictionary SwrvePlugin.prototype.getPersonalizedText = function(text, personalizationProperties, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'getPersonalizedText', [ text, personalizationProperties]); }; SwrvePlugin.prototype.resourcesListenerReady = function() { return cordova.exec(undefined, undefined, 'SwrvePlugin', 'resourcesListenerReady', []); }; SwrvePlugin.prototype.setResourcesListener = function(listener) { window.swrveResourcesUpdatedListener = listener; window.plugins.swrve.resourcesListenerReady(); }; // EmbeddedMessageConfig Listeners Begin SwrvePlugin.prototype.setEmbeddedMessageCallback = function(callback) { window.swrveEmbeddedMessageCallback = callback; } // SwrveInAppMessageConfig Listeners Begin // SwrveInAppMessageListener SwrvePlugin.prototype.setInAppMessageListener = function(listener) { window.swrveInAppMessageListener = listener; window.plugins.swrve.inAppMessageListenerReady(); }; SwrvePlugin.prototype.inAppMessageListenerReady = function() { return cordova.exec(undefined, undefined, 'SwrvePlugin', 'inAppMessageListenerReady', []); }; // SwrveInAppMessageConfig Listeners End SwrvePlugin.prototype.pushNotificationListenerReady = function() { return cordova.exec(undefined, undefined, 'SwrvePlugin', 'pushNotificationListenerReady', []); }; SwrvePlugin.prototype.silentPushNotificationListenerReady = function() { return cordova.exec(undefined, undefined, 'SwrvePlugin', 'silentPushNotificationListenerReady', []); }; SwrvePlugin.prototype.setPushNotificationListener = function(listener) { window.swrvePushNotificationListener = listener; window.plugins.swrve.pushNotificationListenerReady(); }; SwrvePlugin.prototype.setSilentPushNotificationListener = function(listener) { window.swrveSilentPushNotificationListener = listener; window.plugins.swrve.silentPushNotificationListenerReady(); }; SwrvePlugin.prototype.getUserId = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'getUserId', []); }; SwrvePlugin.prototype.getApiKey = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'getApiKey', []); }; SwrvePlugin.prototype.getExternalUserId = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'getExternalUserId', []); }; // userId is a string SwrvePlugin.prototype.identify = function(userId, success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'identify', [ userId ]); }; // userId is a string SwrvePlugin.prototype.start = function(userId, success, fail) { if (!userId || userId.length < 1) { return cordova.exec(success, fail, 'SwrvePlugin', 'start', []); } else { return cordova.exec(success, fail, 'SwrvePlugin', 'start', [ userId ]); } }; SwrvePlugin.prototype.isStarted = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'isStarted', []); }; SwrvePlugin.prototype.stopTracking = function(success, fail) { return cordova.exec(success, fail, 'SwrvePlugin', 'stopTracking', []); }; SwrvePlugin.install = function() { if (!window.plugins) { window.plugins = {}; } window.plugins.swrve = new SwrvePlugin(); // Empty callback for new user resources window.swrveResourcesUpdatedListener = function(resources) {}; window.swrveProcessResourcesUpdated = function(resourcesJson) { // Decode the base64 encoded string sent by the plugin window.swrveResourcesUpdatedListener(JSON.parse(window.atob(resourcesJson))); }; // Empty callback, override this to listen to in-app message actions window.swrveInAppMessageListener = function(action) {}; // Empty callback, override this to listen to silent push notifications window.swrveSilentPushNotificationListener = function(payload) {}; // Empty callback, override this to listen to embedded campaigns window.swrveEmbeddedMessageCallback = function(payload) {}; // Empty callback, override this to listen to push notifications window.swrvePushNotificationListener = function(payload) {}; window.swrveProcessPushNotification = function(base64Payload) { // Decode the base64 encoded string sent by the plugin window.swrvePushNotificationListener(JSON.parse(window.atob(base64Payload))); }; window.swrveProcessSilentPushNotification = function(base64Payload) { // Decode the base64 encoded string sent by the plugin window.swrveSilentPushNotificationListener(JSON.parse(window.atob(base64Payload))); }; return window.plugins.swrve; }; cordova.addConstructor(SwrvePlugin.install);