Add time stamp for hover in Leaflet map? | XM Community
Skip to main content
Solved

Add time stamp for hover in Leaflet map?

  • February 25, 2021
  • 5 replies
  • 115 views

Forum|alt.badge.img

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?

Best answer by ahmedA

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");
     };
    });

5 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • February 25, 2021

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


Forum|alt.badge.img
  • Author
  • February 25, 2021

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");
     };
    });


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • Answer
  • February 26, 2021

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");
     };
    });


Forum|alt.badge.img
  • Author
  • February 26, 2021

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?


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • February 26, 2021

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");
    };
});