Expand my Community achievements bar.

SOLVED

Configuring Different Marketo Munchkin Code to specific site environments under Analytics extension

Avatar

Level 1

Team,

 

Anyone had a chance to load unique Marketo munchkin code specific to environments under the Adobe Analytics extension code editor.

 

I need to load the unique munchkin code to the different environment. Like Sandbox Marketo Munchkin code to load only in DEV/QA/UAT site.and Production Marketo Munchkin code only in Live site.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @RoystonPr  ,

I dont think there is a way to do this in extension itself. You have to rely on custom code.

You can use custom code Adobe Launch rule action to set munchkin ID basis hostname/ URL as per your needs.

Below is sample code how you can achieve. Set Rule Event as "Core - DOM Ready" or "Core - Window Loaded" or "Core - Library Loaded" based on your need.(Any one event)

Set the action as a custom code with below code (Sample code needs to be fine tuned as per your needs. You will have to add hostname values along with Marketo ID and wsInfo value). I hope this helps!

 

 

//Define logic to set munchkin ID basis URL/ hostname
var munchkinId = "Your Default Production munchkin ID"
if(window.location.hostname === "Your Dev Website HostName"){
	munchkinId = "Dev Munchkin ID goes here";
}
else if(window.location.hostname === "Your Stage Website HostName"){
	munchkinId = "Stage Munchkin ID goes here";
}
//Munchkin script
(function() {
  var didInit = false;
  function initMunchkin() {
    if(didInit === false) {
      didInit = true;
      Munchkin.init(munchkinId, {"wsInfo":"abcd"});
    }
  }
  var s = document.createElement('script');
  s.type = 'text/javascript';
  s.async = true;
  s.src='//munchkin.marketo.net/munchkin.js';
  s.onreadystatechange = function() {
    if (this.readyState == 'complete' || this.readyState == 'loaded') {
      initMunchkin();
    }
  };
  s.onload = initMunchkin;
  document.getElementsByTagName('head')[0].appendChild(s);
})();

 

 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 2

Hi @RoystonPr  ,

I dont think there is a way to do this in extension itself. You have to rely on custom code.

You can use custom code Adobe Launch rule action to set munchkin ID basis hostname/ URL as per your needs.

Below is sample code how you can achieve. Set Rule Event as "Core - DOM Ready" or "Core - Window Loaded" or "Core - Library Loaded" based on your need.(Any one event)

Set the action as a custom code with below code (Sample code needs to be fine tuned as per your needs. You will have to add hostname values along with Marketo ID and wsInfo value). I hope this helps!

 

 

//Define logic to set munchkin ID basis URL/ hostname
var munchkinId = "Your Default Production munchkin ID"
if(window.location.hostname === "Your Dev Website HostName"){
	munchkinId = "Dev Munchkin ID goes here";
}
else if(window.location.hostname === "Your Stage Website HostName"){
	munchkinId = "Stage Munchkin ID goes here";
}
//Munchkin script
(function() {
  var didInit = false;
  function initMunchkin() {
    if(didInit === false) {
      didInit = true;
      Munchkin.init(munchkinId, {"wsInfo":"abcd"});
    }
  }
  var s = document.createElement('script');
  s.type = 'text/javascript';
  s.async = true;
  s.src='//munchkin.marketo.net/munchkin.js';
  s.onreadystatechange = function() {
    if (this.readyState == 'complete' || this.readyState == 'loaded') {
      initMunchkin();
    }
  };
  s.onload = initMunchkin;
  document.getElementsByTagName('head')[0].appendChild(s);
})();