cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Code-based Actions: Combine functions in Javascript

Code-based Actions: Combine functions in Javascript

JavaScript can be used for several tasks such as detecting if the user is on a Desktop or Mobile device or to check if the user is on the Homepage or a Specific Page. In this example we want to combine these two functions. If the user is on the homepage on a desktop device, we want to trigger a specific event after 5 seconds.

  1. Create functions
  2. Combine functions
  3. Add delayed opening & trigger event

 

1. Create functions

We start by creating two functions. For more details about these functions have a look at:

<script>
 window.desktopcheck = function() {
     var check = false;
     if(window.innerWidth>768){
         check=true;
     }
     return check;
   }

 window.homepagecheck = function() {
     var check = false;
     if(document.location.pathname === "/"){
         check=true;
     }
     return check;
   }
</script>

2. Combine functions

To combine function we want both functions to return true.

<script>

 if(window.desktopcheck() && window.homepagecheck()){
    // Add code
  }

</script>     

3. Add delayed opening and start event

Now let's add the delayed opening and trigger an event.

<script>

// Delayed Opening
setTimeout(function() {
   __flowai_webclient_app.open()
  }, 5000) // 5 secs
  
// Trigger Event
  window.__flowai_webclient_autoTriggerEvent = 'START_CHAT'

</script>


Find the complete code below

<script>
 window.desktopcheck = function() {
     var check = false;
     if(window.innerWidth>768){
         check=true;
     }
     return check;
   }

 window.homepagecheck = function() {
     var check = false;
     if(document.location.pathname === "/"){
         check=true;
     }
     return check;
   }

 if(window.desktopcheck() && window.homepagecheck()){
    setTimeout(function() {
       __flowai_webclient_app.open()
       }, 5000) // 5 secs
    window.__flowai_webclient_autoTriggerEvent = 'START_CHAT'
  }
</script>
Labels (1)

Code-based Actions: Combine functions in Javascript

JavaScript can be used for several tasks such as detecting if the user is on a Desktop or Mobile device or to check if the user is on the Homepage or a Specific Page. In this example we want to combine these two functions. If the user is on the homepage on a desktop device, we want to trigger a specific event after 5 seconds.

  1. Create functions
  2. Combine functions
  3. Add delayed opening & trigger event

 

1. Create functions

We start by creating two functions. For more details about these functions have a look at:

<script>
 window.desktopcheck = function() {
     var check = false;
     if(window.innerWidth>768){
         check=true;
     }
     return check;
   }

 window.homepagecheck = function() {
     var check = false;
     if(document.location.pathname === "/"){
         check=true;
     }
     return check;
   }
</script>

2. Combine functions

To combine function we want both functions to return true.

<script>

 if(window.desktopcheck() && window.homepagecheck()){
    // Add code
  }

</script>     

3. Add delayed opening and start event

Now let's add the delayed opening and trigger an event.

<script>

// Delayed Opening
setTimeout(function() {
   __flowai_webclient_app.open()
  }, 5000) // 5 secs
  
// Trigger Event
  window.__flowai_webclient_autoTriggerEvent = 'START_CHAT'

</script>


Find the complete code below

<script>
 window.desktopcheck = function() {
     var check = false;
     if(window.innerWidth>768){
         check=true;
     }
     return check;
   }

 window.homepagecheck = function() {
     var check = false;
     if(document.location.pathname === "/"){
         check=true;
     }
     return check;
   }

 if(window.desktopcheck() && window.homepagecheck()){
    setTimeout(function() {
       __flowai_webclient_app.open()
       }, 5000) // 5 secs
    window.__flowai_webclient_autoTriggerEvent = 'START_CHAT'
  }
</script>
Labels (1)

Code-based Actions: Combine functions in Javascript

JavaScript can be used for several tasks such as detecting if the user is on a Desktop or Mobile device or to check if the user is on the Homepage or a Specific Page. In this example we want to combine these two functions. If the user is on the homepage on a desktop device, we want to trigger a specific event after 5 seconds.

  1. Create functions
  2. Combine functions
  3. Add delayed opening & trigger event

 

1. Create functions

We start by creating two functions. For more details about these functions have a look at:

<script>
 window.desktopcheck = function() {
     var check = false;
     if(window.innerWidth>768){
         check=true;
     }
     return check;
   }

 window.homepagecheck = function() {
     var check = false;
     if(document.location.pathname === "/"){
         check=true;
     }
     return check;
   }
</script>

2. Combine functions

To combine function we want both functions to return true.

<script>

 if(window.desktopcheck() && window.homepagecheck()){
    // Add code
  }

</script>     

3. Add delayed opening and start event

Now let's add the delayed opening and trigger an event.

<script>

// Delayed Opening
setTimeout(function() {
   __flowai_webclient_app.open()
  }, 5000) // 5 secs
  
// Trigger Event
  window.__flowai_webclient_autoTriggerEvent = 'START_CHAT'

</script>


Find the complete code below

<script>
 window.desktopcheck = function() {
     var check = false;
     if(window.innerWidth>768){
         check=true;
     }
     return check;
   }

 window.homepagecheck = function() {
     var check = false;
     if(document.location.pathname === "/"){
         check=true;
     }
     return check;
   }

 if(window.desktopcheck() && window.homepagecheck()){
    setTimeout(function() {
       __flowai_webclient_app.open()
       }, 5000) // 5 secs
    window.__flowai_webclient_autoTriggerEvent = 'START_CHAT'
  }
</script>
Labels (1)
Version history
Last update:
‎06-19-2021 11:36 AM
Updated by:
Contributors