From 8bcc788c0e45ab79e0f4ce80cda3363bb4588399 Mon Sep 17 00:00:00 2001
From: Grégoire Aubert See the method {@link #getUrlPathToJs()} for the details about specification.
+ * Example of implementation with a {@link org.sonar.api.server.ws.WebService}:
+ *
+ * The returned path must not start with a slash '/' and must not contain ".." or "://".
+ *
+ * Examples:
+ *
+ * import java.io.IOException;
+ * import java.io.OutputStream;
+ * import java.nio.charset.StandardCharsets;
+ * import org.apache.commons.io.IOUtils;
+ * import org.sonar.api.server.ws.Request;
+ * import org.sonar.api.server.ws.RequestHandler;
+ * import org.sonar.api.server.ws.Response;
+ * import org.sonar.api.server.ws.WebService;
+ * import org.sonar.api.web.WebAnalytics;
+ *
+ * public class MyWebAnalytics implements WebAnalytics, WebService, RequestHandler {
+ *
+ * {@literal @}Override
+ * public String getUrlPathToJs() {
+ * return "api/myplugin/analytics";
+ * }
+ *
+ * {@literal @}Override
+ * public void define(Context context) {
+ * NewController controller = context.createController("api/myplugin");
+ * controller.createAction("analytics")
+ * .setInternal(false)
+ * .setHandler(this);
+ * controller.done();
+ * }
+ *
+ * {@literal @}Override
+ * public void handle(Request request, Response response) throws IOException {
+ * try (OutputStream output = response.stream()
+ * .setMediaType("application/javascript")
+ * .output()) {
+ * IOUtils.write("{replace with the javascript content}", output, StandardCharsets.UTF_8);
+ * }
+ * }
+ * }
+ *
+ *
+ * @since 7.8
+ */
+@ServerSide
+@ExtensionPoint
+public interface WebAnalytics {
+
+ /**
+ * Returns the URL path to the Javascript file that will be loaded by the webapp. File must be
+ * provided by SonarQube server and can't be located outside.
+ *
+ *
+ *
+ *
+ * Webapp does not load the Javascript file if the URL does not return HTTP code 200. + *
+ * + *+ * The Javascript file is composed of two parts: + *
+ * var _paq = window._paq || []; + * // tracker methods like "setCustomDimension" should be called before "trackPageView" + * _paq.push(["trackPageView"]); + * _paq.push(["enableLinkTracking"]); + * (function() { + * var u = "https://me.matomo.cloud/"; + * _paq.push(["setTrackerUrl", u + "matomo.php"]); + * _paq.push(["setSiteId", "12345"]); + * var d = document, + * g = d.createElement("script"), + * s = d.getElementsByTagName("script")[0]; + * g.type = "text/javascript"; + * g.async = true; + * g.defer = true; + * g.src = "//cdn.matomo.cloud/me.matomo.cloud/matomo.js"; + * s.parentNode.insertBefore(g, s); + * })(); + * + * window.setWebAnalyticsPageChangeHandler(function(pathname) { + * _paq.push(["setCustomUrl", pathname]); + * _paq.push(["setDocumentTitle", document.title]); + * _paq.push(["trackPageView"]); + * }); + *+ */ + String getUrlPathToJs(); + +} -- cgit v1.2.3