Sha256: ed8ca2391ed10c7db2cf94a8b7c6170a88c59c7906d530832f470f36b7c50953

Contents?: true

Size: 1.61 KB

Versions: 68

Compression:

Stored size: 1.61 KB

Contents

;(function() {
  "use strict";

  var eventClient;

  $(document).on("page:change", function() {
    if ($("body").data("trackEvents")) {
      logRenderEvent();

      // add listeners to clickable elements
      $(document).on("click", "a, button, input, textarea, option, .btn", logClickEvent);
    }
  });

  // set the endpoint
  eventClient = new EventCaptureClient("/event_capture/events");

  function logRenderEvent() {
    var payload;

    payload = {
      currentUrl: window.location.href,
      headers: grabHeaders(),
      ua: window.navigator.userAgent
    };
    eventClient.log({ kind: "render", payload: payload });
  }

  function logClickEvent(event) {
    var targetElement, payload;

    targetElement = $(event.target);

    if (targetElement.data("clickTimestamp") === event.timeStamp) {
      // this click has already been logged
      return;
    } else {
      // log this click
      targetElement.data("clickTimestamp", event.timeStamp);
    }

    payload = {
      currentUrl: window.location.href,
      buttonHtml: outerHtml(targetElement),
      parentHtml: outerHtml(targetElement.parent()),
      headers: grabHeaders()
    };
    eventClient.log({ kind: "click", payload: payload });
  }

  function grabHeaders() {
    var headers = $("h1, h2").text().split(/\s\s+/);
    var cleaned = [];

    for (var i = 0; i < headers.length; i++) {
      if (headers[i] !== "") {
        cleaned.push(headers[i]);
      }
    }

    return cleaned;
  }

  function outerHtml(el) {
    // because .outerHTML() may not be implemented in all target browsers
    return el.clone().wrap("<p>").parent().html();
  }
})();

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.22.8 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.22.7 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.22.6 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.22.5 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.22.4 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.22.2 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.22.1 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.22.0 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.21.2 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.21.1 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.21.0 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.20.1 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.9 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.8 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.7 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.6 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.5 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.4 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.3 app/assets/javascripts/think_feel_do_engine/event_capture/init.js