Skip to content

Commit 436be26

Browse files
authored
Add presence checks for marketo global objects for V2 integration (#641)
1 parent 0c0f9eb commit 436be26

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

integrations/marketo-v2/HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
4.0.2 / 2021-10-26
2+
=================
3+
4+
* Add better error handling for when Marketo scripts are blocked
5+
16
4.0.0 / 2021-09-09
27
=================
38

integrations/marketo-v2/lib/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ Marketo.prototype.initialize = function() {
133133

134134
var self = this;
135135
this.load(function() {
136+
if (window.Munchkin === undefined) {
137+
return;
138+
}
139+
136140
window.Munchkin.init(munchkinId, {
137141
asyncOnly: true
138142
});
@@ -146,6 +150,10 @@ Marketo.prototype.initialize = function() {
146150
});
147151

148152
this.load('forms', { marketoHostUrl: marketoHostUrl }, function() {
153+
if (window.MktoForms2 === undefined) {
154+
return;
155+
}
156+
149157
var marketoForm = document.createElement('form');
150158
marketoForm.setAttribute('id', 'mktoForm_' + marketoFormId);
151159
marketoForm.setAttribute('style', 'display:none');
@@ -185,6 +193,11 @@ Marketo.prototype.page = function(page) {
185193

186194
var properties = page.properties();
187195
var parsed = url.parse(properties.url);
196+
197+
if (window.mktoMunchkinFunction === undefined) {
198+
return;
199+
}
200+
188201
window.mktoMunchkinFunction('visitWebPage', {
189202
url: properties.url,
190203
params: parsed.query
@@ -273,6 +286,10 @@ Marketo.prototype.identify = function(identify) {
273286
}
274287
}, settings.traits);
275288

289+
if (window.MktoForms2 === undefined) {
290+
return;
291+
}
292+
276293
window.MktoForms2.whenReady(function(form) {
277294
var marketoFormId = parseInt(settings.marketoFormId, 10);
278295
var validFormId = !(Number.isNaN(marketoFormId) || marketoFormId <= 0);

integrations/marketo-v2/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-marketo-v2",
33
"description": "The Marketo analytics.js integration.",
4-
"version": "4.0.1",
4+
"version": "4.0.2",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

0 commit comments

Comments
 (0)