SOLVED

Trigger email on click of a link in webpage using campaign

Go to solution
saurabhmehta13
Level 2

Trigger email on click of a link in webpage using campaign

Hi Experts,

I have injected munchkins js in my webpage using following code:

<script type="text/javascript">
      (function() {
        var didInit = false;
        function initMunchkin() {
          if(didInit === false) {
            didInit = true;
            Munchkin.init('token-AAA');
          }
        }
        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);
        document.onclick = function(event) {
          event = event || window.event; // IE specials
          var target = event.target;
          if(target.nodeName === "A") {
              var urlThatWasClicked = 'https://console.someurl.com/dashboard';
              Munchkin.munchkinFunction("visitWebPage", {
                url : urlThatWasClicked
              });
          }
        };
      })();
 </script>

 

On Click of the link, I want to send email using campaign.

I created a campaign and following is the smart list configuration:
smart_list.png

and following is the flow configuration:

flow.png

In the scheduled tab I have activated the campaign.

Now as soon I link on the link in my webpage, email should be sent to the email ID specified in "To Other Emails" but it's not working. Am I missing anything here?

Really appreciate your inputs on this.

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Trigger email on click of a link in webpage using campaign

Thanks for making that change.

 

There are several problems with your code.

 

  1.  No need to insert your custom listener inside the standard Munchkin init routine. Keep it in a separate function or else it can easily be replaced by someone updating the embed code.
  2. You don't need the legacy event || window.event, I doubt your site actually supports IE 8.
  3. You should not use document.onclick. Use non-intrusive document.addEventListener.
  4. You can't just force all <a> clicks to issue a visitWebPage, when the ones Munchkin supports are already bound to clickLink! This will create duplicates depending on network conditions, which will be very hard to troubleshoot. 

You need to identify your special links so only those links become custom visitWebPage calls.

 

Do this by decorating the interesting links with an HTML data- attribute. 

 

Then look for that attribute and only send the custom call if it exists. Note: if you have a link that would ordinarily be logged (as a clickLink) by Munchkin, and you want to control it with your custom code instead, add class="mchNoDecorate" to the link.

 

 

<a data-munchkin-log-as-visit href="#internal-navigation">Some app menu item</a>
<script>
 document.addEventListener("click", function(event) {
          if( event.target.hasAttribute("data-munchkin-log-as-visit") ) {
              var urlThatWasClicked = 'https://console.someurl.com/dashboard';
              Munchkin.munchkinFunction("visitWebPage", {
                url : urlThatWasClicked
              });
          }
        });
</script>

 

 

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Trigger email on click of a link in webpage using campaign

Please don't post screenshots of code, post actual text highlighted using the syntax highlighter.

 

syntax_js.png

 

After you delete the image and replace it with text, we'll continue.

saurabhmehta13
Level 2

Re: Trigger email on click of a link in webpage using campaign

I updated image with code snipped. Kindly share your inputs.

SanfordWhiteman
Level 10 - Community Moderator

Re: Trigger email on click of a link in webpage using campaign

Thanks for making that change.

 

There are several problems with your code.

 

  1.  No need to insert your custom listener inside the standard Munchkin init routine. Keep it in a separate function or else it can easily be replaced by someone updating the embed code.
  2. You don't need the legacy event || window.event, I doubt your site actually supports IE 8.
  3. You should not use document.onclick. Use non-intrusive document.addEventListener.
  4. You can't just force all <a> clicks to issue a visitWebPage, when the ones Munchkin supports are already bound to clickLink! This will create duplicates depending on network conditions, which will be very hard to troubleshoot. 

You need to identify your special links so only those links become custom visitWebPage calls.

 

Do this by decorating the interesting links with an HTML data- attribute. 

 

Then look for that attribute and only send the custom call if it exists. Note: if you have a link that would ordinarily be logged (as a clickLink) by Munchkin, and you want to control it with your custom code instead, add class="mchNoDecorate" to the link.

 

 

<a data-munchkin-log-as-visit href="#internal-navigation">Some app menu item</a>
<script>
 document.addEventListener("click", function(event) {
          if( event.target.hasAttribute("data-munchkin-log-as-visit") ) {
              var urlThatWasClicked = 'https://console.someurl.com/dashboard';
              Munchkin.munchkinFunction("visitWebPage", {
                url : urlThatWasClicked
              });
          }
        });
</script>

 

 

View solution in original post

saurabhmehta13
Level 2

Re: Trigger email on click of a link in webpage using campaign

Thanks. This is really helpful.

I missed a part of documentation where it says -

In order to be associated to a known record in Marketo, one of the following things must occur:

  • The lead must visit a Munchkin-tracked page with an mkt_tok parameter in the querysytring from a tracked Marketo email link.
  • The lead must fill out a Marketo Form.
  • A Munchkin associateLead call must be sent to your Marketo instance.
  • A SOAP syncLead or REST Associate Lead call must be sent.

Once I added marketo form and submitted it, my emails were getting triggered.