Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorTimo Besenreuther <timo.besenreuther@gmail.com>2013-03-27 12:59:04 +0400
committerTimo Besenreuther <timo.besenreuther@gmail.com>2013-03-27 12:59:04 +0400
commitf56c9d6548778aea63e872ec125f4867e62def1c (patch)
treefa576a43d3079292e35aa4dc9bd1154a5dc09e37 /js
parentbdf12d27b0eada820acd5210c94b21ab26466f95 (diff)
refs #1700 performance tracking in piwik.js
* by default, send performance.timing.responseEnd - performance.timing.requestStart as generation time with the tracking request * if the performance.timing API is not supported by the browser, don't send the metric * new method disablePerformanceTracking() * new method setGenerationTimeMs(generationTime) to set the generation after measuring it on the server side
Diffstat (limited to 'js')
-rw-r--r--js/piwik.js37
1 files changed, 36 insertions, 1 deletions
diff --git a/js/piwik.js b/js/piwik.js
index 5296f218a2..5ad1d9dc14 100644
--- a/js/piwik.js
+++ b/js/piwik.js
@@ -396,7 +396,8 @@ if (typeof JSON2 !== 'object') {
addEventListener, attachEvent, removeEventListener, detachEvent, disableCookies,
cookie, domain, readyState, documentElement, doScroll, title, text,
location, top, document, referrer, parent, links, href, protocol, name, GearsFactory,
- event, which, button, srcElement, type, target,
+ performance, mozPerformance, msPerformance, webkitPerformance, timing, requestStart,
+ responseEnd, event, which, button, srcElement, type, target,
parentNode, tagName, hostname, className,
userAgent, cookieEnabled, platform, mimeTypes, enabledPlugin, javaEnabled,
XMLHttpRequest, ActiveXObject, open, setRequestHeader, onreadystatechange, send, readyState, status,
@@ -460,6 +461,9 @@ if (typeof Piwik !== 'object') {
navigatorAlias = navigator,
screenAlias = screen,
windowAlias = window,
+
+ /* performance timing */
+ performanceAlias = windowAlias.performance || windowAlias.mozPerformance || windowAlias.msPerformance || windowAlias.webkitPerformance,
/* DOM Ready */
hasLoaded = false,
@@ -1157,6 +1161,12 @@ if (typeof Piwik !== 'object') {
// Life of the referral cookie (in milliseconds)
configReferralCookieTimeout = 15768000000, // 6 months
+
+ // Is performance tracking enabled
+ configPerformanceTrackingEnabled = true,
+
+ // Generation time set from the server
+ configPerformanceGenerationTime = 0,
// Custom Variables read from cookie, scope "visit"
customVariables = false,
@@ -1736,6 +1746,14 @@ if (typeof Piwik !== 'object') {
setCookie(cvarname, JSON2.stringify(customVariables), configSessionCookieTimeout, configCookiePath, configCookieDomain);
}
+
+ // performance tracking
+ if (configPerformanceTrackingEnabled && configPerformanceGenerationTime) {
+ request += '&generation_time_ms=' + configPerformanceGenerationTime;
+ } else if (configPerformanceTrackingEnabled && performanceAlias && performanceAlias.timing
+ && performanceAlias.timing.requestStart && performanceAlias.timing.responseEnd) {
+ request += '&generation_time_ms=' + (performanceAlias.timing.responseEnd - performanceAlias.timing.requestStart);
+ }
// update cookies
setVisitorIdCookie(uuid, createTs, visitCount, nowTs, lastVisitTs, isDefined(currentEcommerceOrderTs) && String(currentEcommerceOrderTs).length ? currentEcommerceOrderTs : lastEcommerceOrderTs);
@@ -2704,6 +2722,23 @@ if (typeof Piwik !== 'object') {
}
},
+ /**
+ * Disable automatic performance tracking
+ */
+ disablePerformanceTracking: function () {
+ configPerformanceTrackingEnabled = false;
+ },
+
+ /**
+ * Set the server generation time.
+ * If set, the browser's performance.timing API in not used anymore to determine the time.
+ *
+ * @param int generationTime
+ */
+ setGenerationTimeMs: function(generationTime) {
+ configPerformanceGenerationTime = parseInt(generationTime, 10);
+ },
+
/**
* Set heartbeat (in seconds)
*