Skip to content

Commit

Permalink
Merge pull request #21 from driveback/develop
Browse files Browse the repository at this point in the history
onReady duplications fix
  • Loading branch information
ConstantineYurevich committed Mar 30, 2016
2 parents ee9d225 + 10b635d commit ec7a002
Show file tree
Hide file tree
Showing 11 changed files with 584 additions and 51 deletions.
270 changes: 236 additions & 34 deletions dist/dd-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5945,8 +5945,9 @@ var Integration = (function (_EventEmitter) {
// abstract
};

Integration.prototype.enrichDigitalData = function enrichDigitalData() {
Integration.prototype.enrichDigitalData = function enrichDigitalData(done) {
// abstract
done();
};

Integration.prototype.trackEvent = function trackEvent() {
Expand Down Expand Up @@ -5989,15 +5990,19 @@ var _SegmentStream = require('./integrations/SegmentStream.js');

var _SegmentStream2 = _interopRequireDefault(_SegmentStream);

var _SendPulse = require('./integrations/SendPulse.js');

var _SendPulse2 = _interopRequireDefault(_SendPulse);

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { 'default': obj };
}

var integrations = (_integrations = {}, _integrations[_GoogleAnalytics2['default'].getName()] = _GoogleAnalytics2['default'], _integrations[_GoogleTagManager2['default'].getName()] = _GoogleTagManager2['default'], _integrations[_FacebookPixel2['default'].getName()] = _FacebookPixel2['default'], _integrations[_Driveback2['default'].getName()] = _Driveback2['default'], _integrations[_RetailRocket2['default'].getName()] = _RetailRocket2['default'], _integrations[_SegmentStream2['default'].getName()] = _SegmentStream2['default'], _integrations);
var integrations = (_integrations = {}, _integrations[_GoogleAnalytics2['default'].getName()] = _GoogleAnalytics2['default'], _integrations[_GoogleTagManager2['default'].getName()] = _GoogleTagManager2['default'], _integrations[_FacebookPixel2['default'].getName()] = _FacebookPixel2['default'], _integrations[_Driveback2['default'].getName()] = _Driveback2['default'], _integrations[_RetailRocket2['default'].getName()] = _RetailRocket2['default'], _integrations[_SegmentStream2['default'].getName()] = _SegmentStream2['default'], _integrations[_SendPulse2['default'].getName()] = _SendPulse2['default'], _integrations);

exports['default'] = integrations;

},{"./integrations/Driveback.js":75,"./integrations/FacebookPixel.js":76,"./integrations/GoogleAnalytics.js":77,"./integrations/GoogleTagManager.js":78,"./integrations/RetailRocket.js":79,"./integrations/SegmentStream.js":80}],58:[function(require,module,exports){
},{"./integrations/Driveback.js":75,"./integrations/FacebookPixel.js":76,"./integrations/GoogleAnalytics.js":77,"./integrations/GoogleTagManager.js":78,"./integrations/RetailRocket.js":79,"./integrations/SegmentStream.js":80,"./integrations/SendPulse.js":81}],58:[function(require,module,exports){
'use strict';

function _typeof2(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
Expand Down Expand Up @@ -6140,43 +6145,46 @@ function _prepareGlobals() {
}

function _initializeIntegrations(settings, onReady) {
var ready = (0, _after2['default'])((0, _size2['default'])(_integrations), onReady);

if (settings && (typeof settings === 'undefined' ? 'undefined' : _typeof(settings)) === 'object') {
var integrationSettings = settings.integrations;
if (integrationSettings) {
(0, _each2['default'])(integrationSettings, function (name, options) {
if (typeof _availableIntegrations[name] === 'function') {
var integration = new _availableIntegrations[name](_digitalData, (0, _componentClone2['default'])(options));
ddManager.addIntegration(integration);
}
});
}
(function () {
var integrationSettings = settings.integrations;
if (integrationSettings) {
(0, _each2['default'])(integrationSettings, function (name, options) {
if (typeof _availableIntegrations[name] === 'function') {
var integration = new _availableIntegrations[name](_digitalData, (0, _componentClone2['default'])(options));
ddManager.addIntegration(integration);
}
});
}

if ((0, _size2['default'])(_integrations) > 0) {
(0, _each2['default'])(_integrations, function (name, integration) {
if (!integration.isLoaded() || integration.getOption('noConflict')) {
integration.once('ready', function () {
integration.enrichDigitalData();
_eventManager.addCallback(['on', 'event', function (event) {
integration.trackEvent(event);
}]);
var ready = (0, _after2['default'])((0, _size2['default'])(_integrations), onReady);

if ((0, _size2['default'])(_integrations) > 0) {
(0, _each2['default'])(_integrations, function (name, integration) {
if (!integration.isLoaded() || integration.getOption('noConflict')) {
integration.once('ready', function () {
integration.enrichDigitalData(function () {
_eventManager.addCallback(['on', 'event', function (event) {
integration.trackEvent(event);
}]);
ready();
});
});
integration.initialize();
} else {
ready();
});
integration.initialize();
} else {
ready();
}
});
} else {
ready();
}
}
});
} else {
ready();
}
})();
}
}

ddManager = {

VERSION: '1.0.9',
VERSION: '1.0.10',

setAvailableIntegrations: function setAvailableIntegrations(availableIntegrations) {
_availableIntegrations = availableIntegrations;
Expand Down Expand Up @@ -6774,7 +6782,7 @@ _ddManager2['default'].processEarlyStubCalls();

window.ddManager = _ddManager2['default'];

},{"./availableIntegrations.js":57,"./ddManager.js":58,"./polyfill.js":81}],75:[function(require,module,exports){
},{"./availableIntegrations.js":57,"./ddManager.js":58,"./polyfill.js":82}],75:[function(require,module,exports){
'use strict';

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
Expand Down Expand Up @@ -8297,9 +8305,10 @@ var SegmentStream = (function (_Integration) {

SegmentStream.prototype.reset = function reset() {
(0, _deleteProperty2['default'])(window, 'ssApi');
localStorage.clear();
};

SegmentStream.prototype.enrichDigitalData = function enrichDigitalData() {
SegmentStream.prototype.enrichDigitalData = function enrichDigitalData(done) {
var _this3 = this;

function lowercaseFirstLetter(string) {
Expand All @@ -8312,6 +8321,7 @@ var SegmentStream = (function (_Integration) {
var key = lowercaseFirstLetter(name);
_this3._digitalData.user.ssAttributes[key] = value;
});
done();
};

SegmentStream.prototype.trackEvent = function trackEvent(event) {
Expand Down Expand Up @@ -8354,6 +8364,198 @@ exports['default'] = SegmentStream;
},{"./../Integration.js":56,"./../functions/deleteProperty.js":60,"./../functions/each.js":61}],81:[function(require,module,exports){
'use strict';

function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }

exports.__esModule = true;

var _Integration2 = require('./../Integration.js');

var _Integration3 = _interopRequireDefault(_Integration2);

var _deleteProperty = require('./../functions/deleteProperty.js');

var _deleteProperty2 = _interopRequireDefault(_deleteProperty);

var _each = require('./../functions/each.js');

var _each2 = _interopRequireDefault(_each);

var _componentType = require('component-type');

var _componentType2 = _interopRequireDefault(_componentType);

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { 'default': obj };
}

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}

function _possibleConstructorReturn(self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}return call && ((typeof call === 'undefined' ? 'undefined' : _typeof(call)) === "object" || typeof call === "function") ? call : self;
}

function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + (typeof superClass === 'undefined' ? 'undefined' : _typeof(superClass)));
}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}

var SendPulse = (function (_Integration) {
_inherits(SendPulse, _Integration);

function SendPulse(digitalData, options) {
_classCallCheck(this, SendPulse);

var optionsWithDefaults = Object.assign({
protocol: 'http',
pushScriptUrl: '',
pushSubscriptionTriggerEvent: 'Agreed to Receive Push Notifications'
}, options);

var _this = _possibleConstructorReturn(this, _Integration.call(this, digitalData, optionsWithDefaults));

_this.addTag({
type: 'script',
attr: {
charset: 'UTF-8',
src: _this.getOption('pushScriptUrl')
}
});
return _this;
}

SendPulse.getName = function getName() {
return 'SendPulse';
};

SendPulse.prototype.initialize = function initialize() {
var _this2 = this;

window.ddListener.push(['on', 'change:user', function (user) {
if (user.pushNotifications.isSubscribed) {
_this2.sendUserAttributes(user);
}
}]);
this.load(function () {
var original = window.oSpP.storeSubscription;
window.oSpP.storeSubscription = function (value) {
original(value);
if (value !== 'DENY') {
_this2.sendUserAttributes(_this2._digitalData.user);
}
};
_this2.ready();
});
};

SendPulse.prototype.enrichDigitalData = function enrichDigitalData(done) {
var pushNotification = this._digitalData.user.pushNotifications = {};
try {
pushNotification.isSupported = this.checkPushNotificationsSupport();
this.getPushSubscriptionInfo(function (subscriptionInfo) {
if (subscriptionInfo === undefined) {
pushNotification.isSubscribed = false;
if (window.oSpP.isSafariNotificationSupported()) {
var info = window.safari.pushNotification.permission('web.com.sendpulse.push');
if (info.persmission === 'denied') {
pushNotification.isDenied = true;
}
}
} else {
if (subscriptionInfo.value === 'DENY') {
pushNotification.isSubscribed = false;
pushNotification.isDenied = true;
} else {
pushNotification.isSubscribed = true;
pushNotification.subscriptionId = subscriptionInfo.value;
}
}
done();
});
} catch (e) {
pushNotification.isSupported = false;
done();
}
};

SendPulse.prototype.checkPushNotificationsSupport = function checkPushNotificationsSupport() {
var oSpP = window.oSpP;

if (!oSpP.detectSite()) {
return false;
}
if (oSpP.detectOs() === 'iOS') {
return false;
}
var os = oSpP.detectOs();
var browserInfo = oSpP.detectBrowser();
var browserName = browserInfo.name.toLowerCase();
if (browserName === 'chrome' && parseFloat(browserInfo.version) < 42) {
return false;
}
if (browserName === 'firefox' && parseFloat(browserInfo.version) < 44) {
return false;
}
if (browserName === 'firefox' && os === 'Android') {
return false;
}
if (browserName === 'safari') {
return oSpP.isSafariNotificationSupported();
}
return true;
};

SendPulse.prototype.getPushSubscriptionInfo = function getPushSubscriptionInfo(callback) {
var oSpP = window.oSpP;
oSpP.getDbValue('SPIDs', 'SubscriptionId', function (event) {
callback(event.target.result);
});
};

SendPulse.prototype.sendUserAttributes = function sendUserAttributes(user) {
(0, _each2['default'])(user, function (key, value) {
if ((0, _componentType2['default'])(value) !== 'object') {
window.oSpP.push(key, value);
}
});
};

SendPulse.prototype.isLoaded = function isLoaded() {
return !!window.oSpP;
};

SendPulse.prototype.reset = function reset() {
(0, _deleteProperty2['default'])(window, 'oSpP');
};

SendPulse.prototype.trackEvent = function trackEvent(event) {
if (event.name === this.getOption('pushSubscriptionTriggerEvent')) {
if (this.checkPushNotificationsSupport()) {
var browserInfo = oSpP.detectBrowser();
var browserName = browserInfo.name.toLowerCase();
if (browserName === 'safari') {
window.oSpP.startSubscription();
} else if (browserName === 'chrome' || browserName === 'firefox') {
window.oSpP.showPopUp();
}
}
}
};

return SendPulse;
})(_Integration3['default']);

exports['default'] = SendPulse;

},{"./../Integration.js":56,"./../functions/deleteProperty.js":60,"./../functions/each.js":61,"component-type":6}],82:[function(require,module,exports){
'use strict';

require('core-js/modules/es5');

require('core-js/modules/es6.object.assign');
Expand Down
8 changes: 4 additions & 4 deletions dist/dd-manager.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "digital-data-manager",
"description": "The hassle-free way to integrate Digital Data Layer on your website.",
"author": "Driveback LLC <[email protected]>",
"version": "1.0.9",
"version": "1.0.10",
"license": "MIT",
"main": "dist/dd-manager.js",
"directories": {
Expand Down
3 changes: 2 additions & 1 deletion src/Integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ class Integration extends EventEmitter
// abstract
}

enrichDigitalData() {
enrichDigitalData(done) {
// abstract
done();
}

trackEvent() {
Expand Down
2 changes: 2 additions & 0 deletions src/availableIntegrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Driveback from './integrations/Driveback.js';
import RetailRocket from './integrations/RetailRocket.js';
import FacebookPixel from './integrations/FacebookPixel.js';
import SegmentStream from './integrations/SegmentStream.js';
import SendPulse from './integrations/SendPulse.js';

const integrations = {
[GoogleAnalytics.getName()]: GoogleAnalytics,
Expand All @@ -12,6 +13,7 @@ const integrations = {
[Driveback.getName()]: Driveback,
[RetailRocket.getName()]: RetailRocket,
[SegmentStream.getName()]: SegmentStream,
[SendPulse.getName()]: SendPulse,
};

export default integrations;
Loading

0 comments on commit ec7a002

Please sign in to comment.