I want the Web messaging icon to load only after the submit is clicked

Hello

I want to implement a logic where I have a form and i want the web messaging icon to load only after the user clicks on the submit button but it getting loaded with load of the page. I have tried implementing inside the on click event listener but it is giving error so i created two different script tags.

script>

document.getElementById('submitButton').addEventListener('click', function() {
const form = document.getElementById('userForm');
const formData = new FormData(form);

  let result = {};
  formData.forEach((value, key) => {
    result[key] = value;
  });
  
    let data={
        messaging:{
            customAttributes:result
        }
    }

 Genesys("subscribe", "Database.ready", function() {
     console.log("Database is ready");
        Genesys("command", "Database.set", data,
           function(data)
         {
            console.log("set successfully");
            console.log(data);
        }, 
           function(err){ console.error(err)});
      
  });
    
  document.getElementById('result').innerText = `Captured Data: ${JSON.stringify(result, null, 2)}`;

});

script type="text/javascript" charset="utf-8">

(function (g, e, n, es, ys) {
g['_genesysJs'] = e;
g[e] = g[e] || function () {
(g[e].q = g[e].q || []).push(arguments)
};
g[e].t = 1 * new Date();
g[e].c = es;
ys = document.createElement('script'); ys.async = 1; ys.src = n; ys.charset = 'utf-8'; document.head.appendChild(ys);
})(window, 'Genesys', 'https://apps.aps1.pure.cloud/genesys-bootstrap/genesys.min.js', {
environment: '',
deploymentId: ''
});

There is nothing really in that code to help. First, I would make sure that you have set the Messenger Behaviour so the Launcher button doesn't appear until you trigger it.
image
Second, you can call the Launcher.show command when they press the Submit button (https://developer.genesys.cloud/commdigital/digital/webmessaging/messengersdk/SDKCommandsEvents/launcherPlugin). It should stay until the hide function is used. That might be easier than using listeners. The rest for Database.set is fine and will still work.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.