Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[STRATCONN-3597] | Added Consent signal in Google Tag. #797

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion integrations/google-adwords-new/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var each = require('@ndhoule/each');
var find = require('obj-case');
var reject = require('reject');
var extend = require('extend');
const UNSPECIFIED='unspecified';

/**
* Expose `GoogleAdWordsNew` integration.
Expand All @@ -23,6 +24,12 @@ var GoogleAdWordsNew = (module.exports = integration('Google AdWords New')
.option('defaultPageConversion', '')
.option('disableAdPersonalization', false)
.option('floodlightAccountId', '')
.option('enableConsentMode',false)
.option('adUserDataConsentState',null)
.option('adPersonalizationConsentState',null)
.option('defaultAdsStorageConsentState',null)
.option('defaultAnalyticsStorageConsentState',null)
.option('waitTimeToUpdateConsentState',0)
// The ID in this line (i.e. the gtag.js ID) does not determine which account(s) will receive data from the tag; rather, it is used to uniquely identify your global site tag. Which account(s) receive data from the tag is determined by calling the config command (and by using the send_to parameter on an event). For instance, if you use Google Analytics, you may already have the gtag.js global site tag installed on your site. In that case, the gtag.js ID may be that of the Google Analytics property where you first obtained the snippet.
.tag(
'<script src="https://www.googletagmanager.com/gtag/js?id={{ accountId }}">'
Expand Down Expand Up @@ -59,7 +66,27 @@ GoogleAdWordsNew.prototype.initialize = function() {
if (self.options.floodlightAccountId) {
window.gtag('config', self.options.floodlightAccountId, config);
}
window.gtag('config', self.options.accountId, config);
window.gtag('config', self.options.accountId, config);

if (self.options.enableConsentMode) {
let consent={};
if(self.options.adUserDataConsentState && self.options.adUserDataConsentState!=UNSPECIFIED){
consent.ad_user_data = self.options.adUserDataConsentState
}
if(self.options.adPersonalizationConsentState && self.options.adPersonalizationConsentState!=UNSPECIFIED){
consent.ad_personalization = self.options.adPersonalizationConsentState
}
if(self.options.defaultAdsStorageConsentState && self.options.defaultAdsStorageConsentState!=UNSPECIFIED){
consent.ad_storage = self.options.defaultAdsStorageConsentState
}
if(self.options.defaultAnalyticsStorageConsentState && self.options.defaultAnalyticsStorageConsentState!=UNSPECIFIED){
consent.analytics_storage = self.options.defaultAnalyticsStorageConsentState
}
if(self.options.waitTimeToUpdateConsentState && self.options.waitTimeToUpdateConsentState>0){
consent.wait_for_update = self.options.waitTimeToUpdateConsentState
}
window.gtag('consent', 'default', consent)
}

self.ready();
});
Expand Down
51 changes: 50 additions & 1 deletion integrations/google-adwords-new/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ describe('Google AdWords New', function() {
}
}
],
defaultPageConversion: 'qnCxCOvxq18Q1ta71QM'
defaultPageConversion: 'qnCxCOvxq18Q1ta71QM',
adUserDataConsentState :'granted',
adPersonalizationConsentState: 'denied',
waitTimeToUpdateConsentState:1000
};

beforeEach(function() {
Expand Down Expand Up @@ -95,6 +98,12 @@ describe('Google AdWords New', function() {
.option('pageLoadConversions', {})
.option('defaultPageConversion', '')
.option('disableAdPersonalization', false)
.option('enableConsentMode',false)
.option('adUserDataConsentState',null)
.option('adPersonalizationConsentState',null)
.option('defaultAdsStorageConsentState',null)
.option('defaultAnalyticsStorageConsentState',null)
.option('waitTimeToUpdateConsentState',0)
.tag(
'<script src="https://www.googletagmanager.com/gtag/js?id={{ accountId }}">'
)
Expand Down Expand Up @@ -162,6 +171,46 @@ describe('Google AdWords New', function() {
analytics.initialize();
analytics.spy(window, 'gtag');
});

it('should add consent signals only if enableConsentMode is set to true', function(done) {
googleadwordsnew.options.enableConsentMode = true;
analytics.once('ready', function() {
analytics.deepEqual(window.gtag.args[2], [
'consent',
'default',
{
wait_for_update: 1000,
ad_user_data: 'granted',
ad_personalization:'denied'
}
]);
done();
});
analytics.initialize();
analytics.spy(window, 'gtag');
});


it('should skip adding those consent signal those are unspecified or null', function(done) {
googleadwordsnew.options.enableConsentMode = true;
googleadwordsnew.options.adPersonalizationConsentState = 'unspecified';
googleadwordsnew.options.defaultAnalyticsStorageConsentState='denied';
analytics.once('ready', function() {
analytics.deepEqual(window.gtag.args[2], [
'consent',
'default',
{
wait_for_update: 1000,
ad_user_data: 'granted',
analytics_storage:'denied'

}
]);
done();
});
analytics.initialize();
analytics.spy(window, 'gtag');
});
});

describe('after loading', function() {
Expand Down
5 changes: 3 additions & 2 deletions integrations/shareasale/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ ShareASale.prototype.orderCompleted = function(track) {
var orderId = track.orderId();
var isRepeat = track.proxy('properties.repeat');
var subtotal = (track.subtotal() || 0).toFixed(2);
var total= (track.total() || 0).toFixed(2)
var orderTotal =
this.options.useTotalAsAmount && track.total()
? track.total().toFixed(2)
: subtotal.toFixed(2);
? total
: subtotal;
var products = track.products();
var currency = track.currency() || this.options.currency;
var coupon = track.coupon() || '';
Expand Down
10 changes: 5 additions & 5 deletions integrations/shareasale/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ describe('ShareASale', function() {
subtotal: 42,
shipping: 10,
tax: 3.5,
total: 55.5,
total: 55,
revenue: 15
});
analytics.loaded(
'<img src="https://shareasale.com/sale.cfm?amount=55.50&tracking=123&transtype=sale&merchantID=bonobos&skulist=&quantitylist=&pricelist=&currency=USD&couponcode=">'
'<img src="https://shareasale.com/sale.cfm?amount=55.00&tracking=123&transtype=sale&merchantID=bonobos&skulist=&quantitylist=&pricelist=&currency=USD&couponcode=">'
);
});

Expand All @@ -93,10 +93,10 @@ describe('ShareASale', function() {
orderId: 123,
shipping: 10,
tax: 3.5,
total: 55.5
total: 55
});
analytics.loaded(
'<img src="https://shareasale.com/sale.cfm?amount=42.00&tracking=123&transtype=sale&merchantID=bonobos&skulist=&quantitylist=&pricelist=&currency=USD&couponcode=">'
'<img src="https://shareasale.com/sale.cfm?amount=41.50&tracking=123&transtype=sale&merchantID=bonobos&skulist=&quantitylist=&pricelist=&currency=USD&couponcode=">'
);
});

Expand Down Expand Up @@ -148,7 +148,7 @@ describe('ShareASale', function() {
total: 55.5
});
analytics.loaded(
'<img src="https://shareasale.com/sale.cfm?amount=42.00&tracking=123&transtype=sale&merchantID=bonobos&skulist=&quantitylist=&pricelist=&currency=USD&couponcode=">'
'<img src="https://shareasale.com/sale.cfm?amount=47.00&tracking=123&transtype=sale&merchantID=bonobos&skulist=&quantitylist=&pricelist=&currency=USD&couponcode=">'
);
});

Expand Down