@segment/analytics.js-integration-appboy
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -0,1 +1,6 @@ | ||
1.5.0 / 2018-04-11 | ||
================== | ||
* Add support for v2 of Braze SDK | ||
1.4.1 / 2017-08-09 | ||
@@ -2,0 +7,0 @@ ================== |
100
lib/index.js
@@ -21,3 +21,12 @@ 'use strict'; | ||
.option('safariWebsitePushId', '') | ||
.option('allowCrawlerActivity', false) | ||
.option('doNotLoadFontAwesome', false) | ||
.option('enableLogging', false) | ||
.option('automaticallyDisplayMessages', true) | ||
.option('localization', 'en') | ||
.option('minimumIntervalBetweenTriggerActionsInSeconds', 30) | ||
.option('openInAppMessagesInNewTab', false) | ||
.option('openNewsFeedCardsInNewTab', false) | ||
.option('sessionTimeoutInSeconds', 30) | ||
.option('requireExplicitInAppMessageDismissal', false) | ||
.option('enableHtmlInAppMessages', false) | ||
@@ -27,6 +36,27 @@ .option('trackAllPages', false) | ||
.option('customEndpoint', '') | ||
.tag('<script src="https://js.appboycdn.com/web-sdk/1.6/appboy.min.js">'); | ||
.option('version', 1) | ||
.tag('v1', '<script src="https://js.appboycdn.com/web-sdk/1.6/appboy.min.js">') | ||
.tag('v2', '<script src="https://js.appboycdn.com/web-sdk/2.1/appboy.min.js">'); | ||
Appboy.prototype.initialize = function() { | ||
var options = this.options; | ||
var customEndpoint; | ||
// Setup custom endpoints | ||
if (options.customEndpoint) { | ||
var endpoint = options.customEndpoint; | ||
var regex = new RegExp('^(http|https)://', 'i'); | ||
customEndpoint = (regex.test(endpoint) ? endpoint : 'https://' + endpoint) + '/api/v3'; | ||
} else if (options.datacenter === 'eu') { | ||
customEndpoint = 'https://sdk.api.appboy.eu/api/v3'; | ||
} | ||
if (Number(options.version) === 2) { | ||
this.initializeV2(customEndpoint); | ||
} else { | ||
this.initializeV1(customEndpoint); | ||
} | ||
}; | ||
/** | ||
* Initialize. | ||
* Initialize v1. | ||
* | ||
@@ -36,3 +66,3 @@ * @api public | ||
Appboy.prototype.initialize = function() { | ||
Appboy.prototype.initializeV1 = function(customEndpoint) { | ||
var options = this.options; | ||
@@ -48,7 +78,7 @@ var self = this; | ||
/* eslint-enable */ | ||
// this is used to test this.loaded | ||
this._shim = window.appboy.initialize; | ||
this.load(function() { | ||
this.load('v1', function() { | ||
var config = {}; | ||
@@ -59,10 +89,5 @@ if (options.safariWebsitePushId) config.safariWebsitePushId = options.safariWebsitePushId; | ||
// Setup custom endpoints | ||
if (options.customEndpoint) { | ||
var endpoint = options.customEndpoint; | ||
var regex = new RegExp('^(http|https)://', 'i'); | ||
config.baseUrl = (regex.test(endpoint) ? endpoint : 'https://' + endpoint) + '/api/v3'; | ||
} else if (options.datacenter === 'eu') { | ||
config.baseUrl = 'https://sdk.api.appboy.eu/api/v3'; | ||
} | ||
if (customEndpoint) config.baseUrl = customEndpoint; | ||
self.initializeTester(options.apiKey, config); | ||
@@ -78,3 +103,52 @@ window.appboy.initialize(options.apiKey, config); | ||
}; | ||
/** | ||
* Initialize v2. | ||
* | ||
* @api public | ||
*/ | ||
Appboy.prototype.initializeV2 = function(customEndpoint) { | ||
var options = this.options; | ||
var userId = this.analytics.user().id(); | ||
/* eslint-disable */ | ||
+function (a, p, P, b, y) { | ||
window.appboy = {}; window.appboyQueue = []; | ||
for (var s = "initialize destroy getDeviceId toggleAppboyLogging setLogger openSession changeUser requestImmediateDataFlush requestFeedRefresh subscribeToFeedUpdates logCardImpressions logCardClick logFeedDisplayed requestInAppMessageRefresh logInAppMessageImpression logInAppMessageClick logInAppMessageButtonClick logInAppMessageHtmlClick subscribeToNewInAppMessages removeSubscription removeAllSubscriptions logCustomEvent logPurchase isPushSupported isPushBlocked isPushGranted isPushPermissionGranted registerAppboyPushMessages unregisterAppboyPushMessages submitFeedback trackLocation stopWebTracking resumeWebTracking wipeData ab ab.User ab.User.Genders ab.User.NotificationSubscriptionTypes ab.User.prototype.getUserId ab.User.prototype.setFirstName ab.User.prototype.setLastName ab.User.prototype.setEmail ab.User.prototype.setGender ab.User.prototype.setDateOfBirth ab.User.prototype.setCountry ab.User.prototype.setHomeCity ab.User.prototype.setLanguage ab.User.prototype.setEmailNotificationSubscriptionType ab.User.prototype.setPushNotificationSubscriptionType ab.User.prototype.setPhoneNumber ab.User.prototype.setAvatarImageUrl ab.User.prototype.setLastKnownLocation ab.User.prototype.setUserAttribute ab.User.prototype.setCustomUserAttribute ab.User.prototype.addToCustomAttributeArray ab.User.prototype.removeFromCustomAttributeArray ab.User.prototype.incrementCustomUserAttribute ab.User.prototype.addAlias ab.InAppMessage ab.InAppMessage.SlideFrom ab.InAppMessage.ClickAction ab.InAppMessage.DismissType ab.InAppMessage.OpenTarget ab.InAppMessage.ImageStyle ab.InAppMessage.TextAlignment ab.InAppMessage.Orientation ab.InAppMessage.CropType ab.InAppMessage.prototype.subscribeToClickedEvent ab.InAppMessage.prototype.subscribeToDismissedEvent ab.InAppMessage.prototype.removeSubscription ab.InAppMessage.prototype.removeAllSubscriptions ab.InAppMessage.Button ab.InAppMessage.Button.prototype.subscribeToClickedEvent ab.InAppMessage.Button.prototype.removeSubscription ab.InAppMessage.Button.prototype.removeAllSubscriptions ab.SlideUpMessage ab.ModalMessage ab.FullScreenMessage ab.HtmlMessage ab.ControlMessage ab.Feed ab.Feed.prototype.getUnreadCardCount ab.Card ab.ClassicCard ab.CaptionedImage ab.Banner ab.WindowUtils display display.automaticallyShowNewInAppMessages display.showInAppMessage display.showFeed display.destroyFeed display.toggleFeed sharedLib".split(" "), i = 0; i < s.length; i++){ | ||
for (var m = s[i], k = appboy, l = m.split("."), j = 0; j < l.length - 1; j++)k = k[l[j]]; k[l[j]] = (new Function("return function " + m.replace(/\./g, "_") + "(){appboyQueue.push(arguments); return true}"))() | ||
} | ||
appboy.getUser = function () { return new appboy.ab.User }; | ||
appboy.getCachedFeed = function () { return new appboy.ab.Feed }; | ||
}(window, document, 'script'); | ||
/* eslint-enable */ | ||
// https://js.appboycdn.com/web-sdk/2.0/doc/module-appboy.html#.initialize | ||
var config = { | ||
safariWebsitePushId: options.safariWebsitePushId, | ||
enableHtmlInAppMessages: options.enableHtmlInAppMessages, | ||
allowCrawlerActivity: options.allowCrawlerActivity, | ||
doNotLoadFontAwesome: options.doNotLoadFontAwesome, | ||
enableLogging: options.enableLogging, | ||
localization: options.localization, | ||
minimumIntervalBetweenTriggerActionsInSeconds: Number(options.minimumIntervalBetweenTriggerActionsInSeconds) || 30, | ||
openInAppMessagesInNewTab: options.openInAppMessagesInNewTab, | ||
openNewsFeedCardsInNewTab: options.openNewsFeedCardsInNewTab, | ||
requireExplicitInAppMessageDismissal: options.requireExplicitInAppMessageDismissal, | ||
sessionTimeoutInSeconds: Number(options.sessionTimeoutInSeconds) || 30 | ||
}; | ||
if (customEndpoint) config.baseUrl = customEndpoint; | ||
this.initializeTester(options.apiKey, config); | ||
window.appboy.initialize(options.apiKey, config); | ||
if (options.automaticallyDisplayMessages) window.appboy.display.automaticallyShowNewInAppMessages(); | ||
if (userId) window.appboy.changeUser(userId); | ||
window.appboy.openSession(); | ||
this.load('v2', this.ready); | ||
}; | ||
// This is used to test window.appboy.initialize | ||
@@ -91,2 +165,4 @@ Appboy.prototype.initializeTester = function() {}; | ||
Appboy.prototype.loaded = function() { | ||
var options = this.options; | ||
if (Number(options.version) === 2) return window.appboyQueue === null; | ||
return window.appboy && window.appboy.initialize !== this._shim; | ||
@@ -93,0 +169,0 @@ }; |
{ | ||
"name": "@segment/analytics.js-integration-appboy", | ||
"description": "The Appboy analytics.js integration.", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "analytics.js", |
@@ -21,3 +21,4 @@ 'use strict'; | ||
trackNamedPages: false, | ||
customEndpoint: '' | ||
customEndpoint: '', | ||
version: 1 | ||
}; | ||
@@ -45,4 +46,13 @@ | ||
.option('apiKey', '') | ||
.option('safariWebsitePushId', '') | ||
.option('allowCrawlerActivity', false) | ||
.option('doNotLoadFontAwesome', false) | ||
.option('enableLogging', false) | ||
.option('automaticallyDisplayMessages', true) | ||
.option('safariWebsitePushId', '') | ||
.option('localization', 'en') | ||
.option('minimumIntervalBetweenTriggerActionsInSeconds', 30) | ||
.option('openInAppMessagesInNewTab', false) | ||
.option('openNewsFeedCardsInNewTab', false) | ||
.option('sessionTimeoutInSeconds', 30) | ||
.option('requireExplicitInAppMessageDismissal', false) | ||
.option('enableHtmlInAppMessages', false) | ||
@@ -52,3 +62,4 @@ .option('trackAllPages', false) | ||
.option('customEndpoint', '') | ||
); | ||
.option('version', 1) | ||
); | ||
}); | ||
@@ -74,2 +85,34 @@ | ||
it('should use initializeV1 if version is set to 1', function(done) { | ||
var V1spy = sinon.spy(appboy, 'initializeV1'); | ||
var V2spy = sinon.spy(appboy, 'initializeV2'); | ||
appboy.options.version = 1; | ||
analytics.once('ready', function() { | ||
try { | ||
assert(V1spy.called); | ||
assert(!V2spy.called); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
analytics.initialize(); | ||
}); | ||
it('should use initializeV2 if version is set to 2', function(done) { | ||
var V1spy = sinon.spy(appboy, 'initializeV1'); | ||
var V2spy = sinon.spy(appboy, 'initializeV2'); | ||
appboy.options.version = 2; | ||
analytics.once('ready', function() { | ||
try { | ||
assert(V2spy.called); | ||
assert(!V1spy.called); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
analytics.initialize(); | ||
}); | ||
it('should set the sdk endpoint to EU datacenter if options.datacenter === eu', function(done) { | ||
@@ -117,7 +160,12 @@ appboy.options.datacenter = 'eu'; | ||
it('should call changeUser if userID is present', function(done) { | ||
analytics.user().id('user-id'); | ||
it('should send Safari Website Push ID if provided in the settings', function(done) { | ||
appboy.options.safariWebsitePushId = 'web.com.example.domain'; | ||
var spy = sinon.spy(appboy, 'initializeTester'); | ||
analytics.once('ready', function() { | ||
assert.equal(window.appboy.getUser().getUserId(), 'user-id'); | ||
done(); | ||
try { | ||
analytics.assert(spy.args[0][1].safariWebsitePushId, options.safariWebsitePushId); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
@@ -127,9 +175,53 @@ analytics.initialize(); | ||
it('should send Safari Website Push ID if provided in the settings', function() { | ||
appboy.options.safariWebsitePushId = 'web.com.example.domain'; | ||
analytics.once('ready', function() { | ||
analytics.assert(appboy.safariWebsitePushId === options.safariWebsitePushId); | ||
describe('initializeV1', function() { | ||
it('should call changeUser if userID is present', function(done) { | ||
analytics.user().id('user-id'); | ||
analytics.once('ready', function() { | ||
assert.equal(window.appboy.getUser().getUserId(), 'user-id'); | ||
done(); | ||
}); | ||
analytics.initialize(); | ||
}); | ||
analytics.initialize(); | ||
}); | ||
describe('initializeV2', function() { | ||
it('should call changeUser if userID is present', function(done) { | ||
appboy.options.version = 2; | ||
analytics.user().id('user-id'); | ||
analytics.once('ready', function() { | ||
window.appboy.getUser().getUserId(function(userId) { | ||
assert.equal(userId, 'user-id'); | ||
done(); | ||
}); | ||
}); | ||
analytics.initialize(); | ||
}); | ||
it('should initialize the appboy sdk with default options if none are provided', function(done) { | ||
appboy.options.version = 2; | ||
var spy = sinon.spy(appboy, 'initializeTester'); | ||
var defaults = { | ||
allowCrawlerActivity: false, | ||
doNotLoadFontAwesome: false, | ||
enableLogging: false, | ||
safariWebsitePushId: '', | ||
localization: 'en', | ||
minimumIntervalBetweenTriggerActionsInSeconds: 30, | ||
openInAppMessagesInNewTab: false, | ||
openNewsFeedCardsInNewTab: false, | ||
sessionTimeoutInSeconds: 30, | ||
requireExplicitInAppMessageDismissal: false, | ||
enableHtmlInAppMessages: false | ||
}; | ||
analytics.once('ready', function() { | ||
try { | ||
assert.deepEqual(spy.args[0][1], defaults); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
analytics.initialize(); | ||
}); | ||
}); | ||
}); | ||
@@ -136,0 +228,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Obfuscated code
Supply chain riskObfuscated files are intentionally packed to hide their behavior. This could be a sign of malware.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Obfuscated code
Supply chain riskObfuscated files are intentionally packed to hide their behavior. This could be a sign of malware.
Found 1 instance in 1 package
310914
15
9028
5
2