Setting up custom event listeners

Customers and technical partners can code in event listeners in customer properties. In this example, the feedback payload is printed to the console when the survey is submitted.

window.addEventListener('MDigital_Submit_Feedback', function(mdEvent) {
 var mdDetail = mdEvent.detail;
 var mdData = mdEvent.detail.Content;
  console.log(mdDetail);
  console.log(mdData);
});

In this example, all Digital events are printed to the console.

<script nonce="2Obg9dyrqzSb6rSM1jSK0w==" >function (window) {

    function withFormContent(acc, data) { acc.content = data.Content; }
    function withFeedbackUUID(acc, data) { acc.feedbackUUID = data.Feedback_UUID; }

    function mEvent(name, action, opts) {

        opts = opts || {};
        var custom = opts.custom;
        var label = opts.label;

        function handle(event) {
            var start = +new Date();
            var cm = window.cm || function () {};
            var mData = event.detail;
            var eData = { category: 'medallia', action: action, label: label || mData.Form_Type, value: mData.Form_ID, myParams: {} };

            if (custom) {
                for (var i = 0; i < custom.length; i++) custom[i](eData.myParams, mData);
            }
            var end = +new Date();
            console.log('send', 'event', eData,end-start);
        }

        window.addEventListener('MDigital_' + name, handle);
    }

    mEvent('ShowForm_Called', 'FormCall');
    mEvent('Form_Displayed', 'FormDisplay');
    mEvent('Form_Next_Page', 'FormNextPage');
    mEvent('Form_Back_Page', 'FormBackPage');
    mEvent('Form_Close_Submitted', 'FormSubmit');
    mEvent('Form_Close_No_Submit', 'FormNoSubmit');
    mEvent('Submit_Feedback', 'FeedbackSubmit', { custom: [withFeedbackUUID, withFormContent] });
    mEvent('Feedback_Button_Clicked', 'FeedbackButton', { custom: [withFeedbackUUID] });
    mEvent('ThankYou_Displayed', 'ThankYouDisplayed', { custom: [withFeedbackUUID] });
    mEvent('Invite_Displayed', 'InviteDisplayed', { label: 'Invite' });
    mEvent('Invite_Accepted', 'InviteAccepted', { label: 'Invite' });
    mEvent('Invite_Declined', 'InviteDeclined', { label: 'Invite' });
    mEvent('Invite_Skipped', 'InviteSkipped', { label: 'Invite' });
}(window));
</script>