Skip to content

Commit

Permalink
Merge pull request #12 from driveback/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ConstantineYurevich committed Feb 13, 2016
2 parents 4f96ef3 + 87e274a commit cb661a5
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 102 deletions.
91 changes: 50 additions & 41 deletions dist/dd-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6542,7 +6542,7 @@ function _prepareGlobals() {

var ddManager = {

VERSION: '1.0.3',
VERSION: '1.0.4',

setAvailableIntegrations: function setAvailableIntegrations(availableIntegrations) {
_availableIntegrations = availableIntegrations;
Expand Down Expand Up @@ -6640,7 +6640,7 @@ var ddManager = {

if ((0, _size2['default'])(_integrations) > 0) {
(0, _each2['default'])(_integrations, function (name, integration) {
if (!integration.isLoaded()) {
if (!integration.isLoaded() || integration.getOption('noConflict')) {
integration.once('ready', ready);
integration.initialize();
} else {
Expand Down Expand Up @@ -7714,7 +7714,8 @@ var GoogleAnalytics = (function (_Integration) {
metrics: {},
dimensions: {},
contentGroupings: {},
namespace: undefined
namespace: undefined,
noConflict: false
}, options);

var _this = _possibleConstructorReturn(this, _Integration.call(this, digitalData, optionsWithDefaults));
Expand All @@ -7737,54 +7738,60 @@ var GoogleAnalytics = (function (_Integration) {
this.pageCalled = false;

// setup the tracker globals
if (!window.ga) {
window.GoogleAnalyticsObject = 'ga';
window.ga = window.ga || function ga() {
window.ga.q = window.ga.q || [];
window.ga.q.push(arguments);
};
window.ga.l = new Date().getTime();
}
window.GoogleAnalyticsObject = 'ga';
window.ga = window.ga || function gaPlaceholder() {
window.ga.q = window.ga.q || [];
window.ga.q.push(arguments);
};
window.ga.l = new Date().getTime();

if (window.location.hostname === 'localhost') {
this.setOption('domain', 'none');
}

window.ga('create', this.getOption('trackingId'), {
// Fall back on default to protect against empty string
cookieDomain: this.getOption('domain'),
siteSpeedSampleRate: this.getOption('siteSpeedSampleRate'),
allowLinker: true,
name: this.getOption('namespace')
});

// display advertising
if (this.getOption('doubleClick')) {
this.ga('require', 'displayfeatures');
}
// https://support.google.com/analytics/answer/2558867?hl=en
if (this.getOption('enhancedLinkAttribution')) {
this.ga('require', 'linkid', 'linkid.js');
}
this.initializeTracker();

// send global id
var userId = this.get('user.id');
if (this.getOption('sendUserId') && userId) {
this.ga('set', 'userId', userId);
if (this.getOption('noConflict')) {
this.ready();
} else {
this.load(this.ready);
}
} else {
this.ready();
}
};

// anonymize after initializing, otherwise a warning is shown
// in google analytics debugger
if (this.getOption('anonymizeIp')) this.ga('set', 'anonymizeIp', true);
GoogleAnalytics.prototype.initializeTracker = function initializeTracker() {
window.ga('create', this.getOption('trackingId'), {
// Fall back on default to protect against empty string
cookieDomain: this.getOption('domain'),
siteSpeedSampleRate: this.getOption('siteSpeedSampleRate'),
allowLinker: true,
name: this.getOption('namespace')
});

// custom dimensions & metrics
var custom = this.getCustomDimensions();
if ((0, _size2['default'])(custom)) this.ga('set', custom);
// display advertising
if (this.getOption('doubleClick')) {
this.ga('require', 'displayfeatures');
}
// https://support.google.com/analytics/answer/2558867?hl=en
if (this.getOption('enhancedLinkAttribution')) {
this.ga('require', 'linkid', 'linkid.js');
}

this.load(this.ready);
} else {
this.ready();
// send global id
var userId = this.get('user.id');
if (this.getOption('sendUserId') && userId) {
this.ga('set', 'userId', userId);
}

// anonymize after initializing, otherwise a warning is shown
// in google analytics debugger
if (this.getOption('anonymizeIp')) this.ga('set', 'anonymizeIp', true);

// custom dimensions & metrics
var custom = this.getCustomDimensions();
if ((0, _size2['default'])(custom)) this.ga('set', custom);
};

GoogleAnalytics.prototype.ga = function ga() {
Expand Down Expand Up @@ -7865,7 +7872,9 @@ var GoogleAnalytics = (function (_Integration) {

GoogleAnalytics.prototype.trackEvent = function trackEvent(event) {
if (this.getOption('trackOnlyCustomEvents')) {
this.onCustomEvent(event);
if (['Viewed Page', 'Viewed Product', 'Clicked Product', 'Viewed Product Detail', 'Added Product', 'Removed Product', 'Completed Transaction', 'Refunded Transaction', 'Viewed Product Category', 'Viewed Checkout Step', 'Completed Checkout Step'].indexOf(event.name) < 0) {
this.onCustomEvent(event);
}
} else {
if (event.name === 'Viewed Page') {
this.onViewedPage(event);
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.3",
"version": "1.0.4",
"license": "MIT",
"main": "dist/dd-manager.js",
"directories": {
Expand Down
4 changes: 2 additions & 2 deletions src/ddManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function _prepareGlobals() {

const ddManager = {

VERSION: '1.0.3',
VERSION: '1.0.4',

setAvailableIntegrations: (availableIntegrations) => {
_availableIntegrations = availableIntegrations;
Expand Down Expand Up @@ -199,7 +199,7 @@ const ddManager = {

if (size(_integrations) > 0) {
each(_integrations, (name, integration) => {
if (!integration.isLoaded()) {
if (!integration.isLoaded() || integration.getOption('noConflict')) {
integration.once('ready', ready);
integration.initialize();
} else {
Expand Down
99 changes: 60 additions & 39 deletions src/integrations/GoogleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class GoogleAnalytics extends Integration {
dimensions: {},
contentGroupings: {},
namespace: undefined,
noConflict: false,
}, options);

super(digitalData, optionsWithDefaults);
Expand All @@ -74,54 +75,60 @@ class GoogleAnalytics extends Integration {
this.pageCalled = false;

// setup the tracker globals
if (!window.ga) {
window.GoogleAnalyticsObject = 'ga';
window.ga = window.ga || function ga() {
window.ga.q = window.ga.q || [];
window.ga.q.push(arguments);
};
window.ga.l = new Date().getTime();
}
window.GoogleAnalyticsObject = 'ga';
window.ga = window.ga || function gaPlaceholder() {
window.ga.q = window.ga.q || [];
window.ga.q.push(arguments);
};
window.ga.l = new Date().getTime();

if (window.location.hostname === 'localhost') {
this.setOption('domain', 'none');
}

window.ga('create', this.getOption('trackingId'), {
// Fall back on default to protect against empty string
cookieDomain: this.getOption('domain'),
siteSpeedSampleRate: this.getOption('siteSpeedSampleRate'),
allowLinker: true,
name: this.getOption('namespace')
});

// display advertising
if (this.getOption('doubleClick')) {
this.ga('require', 'displayfeatures');
}
// https://support.google.com/analytics/answer/2558867?hl=en
if (this.getOption('enhancedLinkAttribution')) {
this.ga('require', 'linkid', 'linkid.js');
}
this.initializeTracker();

// send global id
const userId = this.get('user.id');
if (this.getOption('sendUserId') && userId) {
this.ga('set', 'userId', userId);
if (this.getOption('noConflict')) {
this.ready();
} else {
this.load(this.ready);
}
} else {
this.ready();
}
}

// anonymize after initializing, otherwise a warning is shown
// in google analytics debugger
if (this.getOption('anonymizeIp')) this.ga('set', 'anonymizeIp', true);
initializeTracker() {
window.ga('create', this.getOption('trackingId'), {
// Fall back on default to protect against empty string
cookieDomain: this.getOption('domain'),
siteSpeedSampleRate: this.getOption('siteSpeedSampleRate'),
allowLinker: true,
name: this.getOption('namespace'),
});

// custom dimensions & metrics
const custom = this.getCustomDimensions();
if (size(custom)) this.ga('set', custom);
// display advertising
if (this.getOption('doubleClick')) {
this.ga('require', 'displayfeatures');
}
// https://support.google.com/analytics/answer/2558867?hl=en
if (this.getOption('enhancedLinkAttribution')) {
this.ga('require', 'linkid', 'linkid.js');
}

this.load(this.ready);
} else {
this.ready();
// send global id
const userId = this.get('user.id');
if (this.getOption('sendUserId') && userId) {
this.ga('set', 'userId', userId);
}

// anonymize after initializing, otherwise a warning is shown
// in google analytics debugger
if (this.getOption('anonymizeIp')) this.ga('set', 'anonymizeIp', true);

// custom dimensions & metrics
const custom = this.getCustomDimensions();
if (size(custom)) this.ga('set', custom);
}

ga() {
Expand Down Expand Up @@ -202,7 +209,21 @@ class GoogleAnalytics extends Integration {

trackEvent(event) {
if (this.getOption('trackOnlyCustomEvents')) {
this.onCustomEvent(event);
if ([
'Viewed Page',
'Viewed Product',
'Clicked Product',
'Viewed Product Detail',
'Added Product',
'Removed Product',
'Completed Transaction',
'Refunded Transaction',
'Viewed Product Category',
'Viewed Checkout Step',
'Completed Checkout Step',
].indexOf(event.name) < 0) {
this.onCustomEvent(event);
}
} else {
if (event.name === 'Viewed Page') {
this.onViewedPage(event);
Expand Down Expand Up @@ -415,7 +436,7 @@ class GoogleAnalytics extends Integration {
if (!transaction || !transaction.orderId) return;
this.loadEnhancedEcommerce(transaction.currency);

each(transaction.lineItems, (key, lineItem) => {
each(transaction.lineItems, (key, lineItem) => {
const product = lineItem.product;
if (product) {
product.currency = product.currency || transaction.currency || this.getOption('defaultCurrency');
Expand Down
Loading

0 comments on commit cb661a5

Please sign in to comment.