• I’m not a pro, so please don’t judge too harshly. But I could really use some help:

    I’ve got a messaging interface integrated within my WordPress site that looks something like this:

    <convo data-aspect-ratio="4:3”>
      <a href="#"><span>View experience</span></a>
      <script src="#"></script>
    </convo>
    

    Using postMessage interface and I want to use an event listener to grab event data from the player

    
    window.addEventListener("message", (event) => {
      console.log(event.data); // e.g. <code>speakeasy:ready</code>, <code>speakeasy:maximise</code>, <code>speakeasy:minimise</code>
    });
    

    and add a “roadblock after three questions” functionality:

    
    window.addEventListener("message", (event) => {
      if (event.data.startsWith("speakeasy:response")) {
        doSomething(event.data); 
    });
    

    I’d like to write it in the following format:

    1. On page load, check cookie to see if the user has asked 3 questions
    – If so, check whether the user has subscribed to the email list
    – If so, show a thanks message
    – Else, show the subscription form
    – Else, add the player to the page and listen for events via postMessage
    2. On each postMessage event, if the event type is “response”
    – Increment the responses count on the cookie
    – If responses >= 3, remove or disable the player, and
    – If subscribed === true, show thanks message
    – Else, show subscription form
    3. On subscription form submission, set subscribed to true on the cookie`

    Could you please advice on what would be the best way to tackle this?

    Many thanks,

    Laura

    • This topic was modified 2 years, 2 months ago by laura-work-in-progress.
    • This topic was modified 2 years, 2 months ago by laura-work-in-progress.
    • This topic was modified 2 years, 2 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    This may not help much, but storing data in cookies that’s needed for some sort of enforcement is not very secure. Users can easily remove the data so they appear to be new users.

    The only reliable way to maintain enforcement data is to do so server side. But then you would need to require user login before doing anything because its otherwise very difficult to ensure the requests are coming from the same user.

    You can still manage the user experience client side with JavaScript, but reliable, secure data should be fetched from the server and not saved in cookies. Your JavaScript can fetch any needed server data via Ajax techniques. But if security is not a concern, feel free to use cookies if you prefer.

    Unless you are keen to develop this as a learning experience, try searching for a plugin that already provides the functionality you want. It’ll save you a lot of development time if one can be found.

    If you will be developing your own solution, start by writing out each detailed step you need the code to do in the form of comments. Then work on each discrete step in turn, frequently testing every small part as you go.

Viewing 1 replies (of 1 total)
  • The topic ‘Messaging interface cookie block after 3 questions’ is closed to new replies.