Skip to content

Commit 05e07c7

Browse files
authored
[LIBWEB-926] Add support for Hubspot EU SDK (#645)
Adds option
1 parent 3644ec3 commit 05e07c7

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

integrations/hubspot/HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.2.4 / 2021-11-22
2+
===================
3+
* Add support for HubSpots EU Data Residency with EU script tag.
4+
15
2.2.2 / 2020-12-14
26
===================
37

integrations/hubspot/lib/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ var HubSpot = (module.exports = integration('HubSpot')
2020
.global('hbspt')
2121
.option('portalId', null)
2222
.option('loadFormsSdk', false)
23+
.option('enableEuropeanDataCenter', false)
2324
.tag(
24-
'lib',
25+
'global-tag',
2526
'<script id="hs-analytics" src="https://js.hs-analytics.net/analytics/{{ cacheBuster }}/{{ portalId }}.js">'
2627
)
28+
.tag(
29+
'eu-tag',
30+
'<script id="hs-analytics" src="https://js-eu1.hs-analytics.net/analytics/{{ cacheBuster }}/{{ portalId }}.js">'
31+
)
2732
.tag('forms', '<script src="//js.hsforms.net/forms/shell.js">'));
2833

2934
/**
@@ -37,12 +42,13 @@ HubSpot.prototype.initialize = function() {
3742
var cacheBuster = Math.ceil(new Date() / 300000) * 300000;
3843
var shouldLoadLeadForms = this.options.loadFormsSdk;
3944
var self = this;
45+
var tagName = this.options.enableEuropeanDataCenter ? 'eu-tag' : 'global-tag';
4046
if (shouldLoadLeadForms) {
4147
this.load('forms', function() {
42-
self.load('lib', { cacheBuster: cacheBuster }, self.ready);
48+
self.load(tagName, { cacheBuster: cacheBuster }, self.ready);
4349
});
4450
} else {
45-
this.load('lib', { cacheBuster: cacheBuster }, this.ready);
51+
this.load(tagName, { cacheBuster: cacheBuster }, this.ready);
4652
}
4753
};
4854

integrations/hubspot/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-hubspot",
33
"description": "The Hubspot analytics.js integration.",
4-
"version": "2.2.3",
4+
"version": "2.2.4",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/hubspot/test/index.test.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe('HubSpot', function() {
1111
var hubspot;
1212
var options = {
1313
portalId: 62515,
14-
loadFormsSdk: false
14+
loadFormsSdk: false,
15+
enableEuropeanDataCenter: false
1516
};
1617

1718
beforeEach(function() {
@@ -38,13 +39,20 @@ describe('HubSpot', function() {
3839
.global('hbspt')
3940
.option('loadFormsSdk', false)
4041
.option('portalId', null)
42+
.option('enableEuropeanDataCenter', false)
4143
);
4244
});
4345

4446
describe('before loading', function() {
4547
beforeEach(function() {
4648
analytics.stub(hubspot, 'load');
4749
});
50+
afterEach(function() {
51+
analytics.restore();
52+
analytics.reset();
53+
hubspot.reset();
54+
sandbox();
55+
});
4856

4957
describe('#initialize', function() {
5058
it('should create window._hsq', function() {
@@ -53,6 +61,46 @@ describe('HubSpot', function() {
5361
analytics.page();
5462
analytics.assert(window._hsq instanceof Array);
5563
});
64+
it('should call #load', function() {
65+
analytics.initialize();
66+
analytics.called(hubspot.load);
67+
});
68+
it('initializes with global tag', function() {
69+
var hubspot;
70+
var options = {
71+
portalId: 62515,
72+
enableEuropeanDataCenter: false
73+
};
74+
75+
analytics = new Analytics();
76+
hubspot = new HubSpot(options);
77+
analytics.use(HubSpot);
78+
analytics.use(tester);
79+
analytics.add(hubspot);
80+
81+
analytics.stub(hubspot, 'load');
82+
83+
analytics.initialize();
84+
analytics.called(hubspot.load, 'global-tag');
85+
});
86+
it('initializes with eu tag', function() {
87+
var hubspot;
88+
var options = {
89+
portalId: 62515,
90+
enableEuropeanDataCenter: true
91+
};
92+
93+
analytics = new Analytics();
94+
hubspot = new HubSpot(options);
95+
analytics.use(HubSpot);
96+
analytics.use(tester);
97+
analytics.add(hubspot);
98+
99+
analytics.stub(hubspot, 'load');
100+
101+
analytics.initialize();
102+
analytics.called(hubspot.load, 'eu-tag');
103+
});
56104
});
57105
});
58106

0 commit comments

Comments
 (0)