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.19.2 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.1 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.19.0 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.18.0 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.17.2 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.17.1 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.17.0 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.16.3 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.16.2 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.16.1 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.15.7 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.16.0 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.15.6 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.15.5 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.15.4 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.15.3 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.15.2 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.15.1 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.15.0 app/assets/javascripts/think_feel_do_engine/event_capture/init.js
think_feel_do_engine-3.14.9 app/assets/javascripts/think_feel_do_engine/event_capture/init.js