From ca5afa117f9080f6bd107a98abd834cae86a604f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mari=CC=81n=20Alcaraz?= Date: Wed, 20 Oct 2021 16:40:26 -0700 Subject: [PATCH] Add presence checks for marketo global objects for V2 integration --- integrations/marketo-v2/HISTORY.md | 5 +++++ integrations/marketo-v2/lib/index.js | 17 +++++++++++++++++ integrations/marketo-v2/package.json | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/integrations/marketo-v2/HISTORY.md b/integrations/marketo-v2/HISTORY.md index b00d4a0ec..58f8db445 100644 --- a/integrations/marketo-v2/HISTORY.md +++ b/integrations/marketo-v2/HISTORY.md @@ -1,3 +1,8 @@ +4.0.2 / 2021-10-26 +================= + + * Add better error handling for when Marketo scripts are blocked + 4.0.0 / 2021-09-09 ================= diff --git a/integrations/marketo-v2/lib/index.js b/integrations/marketo-v2/lib/index.js index c62201d2b..789bd102f 100644 --- a/integrations/marketo-v2/lib/index.js +++ b/integrations/marketo-v2/lib/index.js @@ -133,6 +133,10 @@ Marketo.prototype.initialize = function() { var self = this; this.load(function() { + if (window.Munchkin === undefined) { + return; + } + window.Munchkin.init(munchkinId, { asyncOnly: true }); @@ -146,6 +150,10 @@ Marketo.prototype.initialize = function() { }); this.load('forms', { marketoHostUrl: marketoHostUrl }, function() { + if (window.MktoForms2 === undefined) { + return; + } + var marketoForm = document.createElement('form'); marketoForm.setAttribute('id', 'mktoForm_' + marketoFormId); marketoForm.setAttribute('style', 'display:none'); @@ -185,6 +193,11 @@ Marketo.prototype.page = function(page) { var properties = page.properties(); var parsed = url.parse(properties.url); + + if (window.mktoMunchkinFunction === undefined) { + return; + } + window.mktoMunchkinFunction('visitWebPage', { url: properties.url, params: parsed.query @@ -273,6 +286,10 @@ Marketo.prototype.identify = function(identify) { } }, settings.traits); + if (window.MktoForms2 === undefined) { + return; + } + window.MktoForms2.whenReady(function(form) { var marketoFormId = parseInt(settings.marketoFormId, 10); var validFormId = !(Number.isNaN(marketoFormId) || marketoFormId <= 0); diff --git a/integrations/marketo-v2/package.json b/integrations/marketo-v2/package.json index 28d2440e7..b993b23f2 100644 --- a/integrations/marketo-v2/package.json +++ b/integrations/marketo-v2/package.json @@ -1,7 +1,7 @@ { "name": "@segment/analytics.js-integration-marketo-v2", "description": "The Marketo analytics.js integration.", - "version": "4.0.1", + "version": "4.0.2", "keywords": [ "analytics.js", "analytics.js-integration",