Add time stamp for hover in Leaflet map? | XM Community
Solved

Add time stamp for hover in Leaflet map?

  • 25 February 2021
  • 5 replies
  • 61 views

Badge

I'm using Leaflet to insert a map into Qualtrics. For one of my markers, I have it set up so that (1) a popup appears with a mouse hover and (2) clicking on the popup continues on to the next page in the experiment:

marker1.on('mouseover', function (e) {
      this.openPopup();
      this.getPopup()._contentNode.onclick = function () {
      document.querySelector("#NextButton").click();
      Qualtrics.SurveyEngine.setEmbeddedData("home", "one");
     };
    });
Is it also possible to use embedded data to also record when the mouse hover occurs with a time stamp? If so, how?

icon

Best answer by ahmedA 26 February 2021, 01:39

View original

5 replies

Userlevel 7
Badge +21

Use Date.now() and set it as an embedded variable.

Badge

https://www.qualtrics.com/community/discussion/comment/35007#Comment_35007This gets be part way there, but where does it go in my code. Like this?
marker1.on('mouseover', function (e) {
      this.openPopup(
Qualtrics.SurveyEngine.setEmbeddedData("timestamp", "Date.now()");
);
      this.getPopup()._contentNode.onclick = function () {
      document.querySelector("#NextButton").click();
      Qualtrics.SurveyEngine.setEmbeddedData("home", "one");
     };
    });

Userlevel 7
Badge +21

marker1.on('mouseover', function (e) {
      this.openPopup();
Qualtrics.SurveyEngine.setEmbeddedData("timestamp", Date.now());
      this.getPopup()._contentNode.onclick = function () {
      document.querySelector("#NextButton").click();
      Qualtrics.SurveyEngine.setEmbeddedData("home", "one");
     };
    });

Badge

https://www.qualtrics.com/community/discussion/comment/35010#Comment_35010This worked perfectly. Do you have any ideas on how I can handle the fact that people could hover multiple times on marker 1? That is, how can I record multiple instances of this hovering behavior in my survey?

Userlevel 7
Badge +21

var times = 0;
marker1.on("mouseover", function (e) {
    this.openPopup();
    times++;
    Qualtrics.SurveyEngine.setEmbeddedData("timestamp" + times, Date.now());
    this.getPopup()._contentNode.onclick = function () {
        document.querySelector("#NextButton").click();
        Qualtrics.SurveyEngine.setEmbeddedData("home", "one");
    };
});

Leave a Reply