diff options
author | Matthieu Aubry <mattab@users.noreply.github.com> | 2017-05-09 12:42:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-09 12:42:21 +0300 |
commit | 41e37ae7cb965bf152ee9bd60745f454a356f769 (patch) | |
tree | 74576c62377b8658012131860920d161525b75b8 /js/piwik.js | |
parent | 317700513cc732bb2371edbe645555feadbbc545 (diff) | |
parent | 125d502da360f84476ae22a5249ab3db3045d3dd (diff) |
Merge pull request #11679 from piwik/3.x-dev3.0.4-b3
Release Piwik 3.0.4-b3
Diffstat (limited to 'js/piwik.js')
-rw-r--r-- | js/piwik.js | 114 |
1 files changed, 99 insertions, 15 deletions
diff --git a/js/piwik.js b/js/piwik.js index c5a0e2351d..69c95ffe36 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -986,15 +986,15 @@ if (typeof JSON_PIWIK !== 'object' && typeof window.JSON === 'object' && window. setDownloadClasses, setLinkClasses, setCampaignNameKey, setCampaignKeywordKey, discardHashTag, - setCookieNamePrefix, setCookieDomain, setCookiePath, setVisitorIdCookie, - setVisitorCookieTimeout, setSessionCookieTimeout, setReferralCookieTimeout, + setCookieNamePrefix, setCookieDomain, setCookiePath, setVisitorIdCookie, getCookieDomain, hasCookies, setSessionCookie, + setVisitorCookieTimeout, setSessionCookieTimeout, setReferralCookieTimeout, getCookie, getCookiePath, getSessionCookieTimeout, setConversionAttributionFirstReferrer, tracker, request, disablePerformanceTracking, setGenerationTimeMs, doNotTrack, setDoNotTrack, msDoNotTrack, getValuesFromVisitorIdCookie, enableCrossDomainLinking, disableCrossDomainLinking, isCrossDomainLinkingEnabled, addListener, enableLinkTracking, enableJSErrorTracking, setLinkTrackingTimer, getLinkTrackingTimer, enableHeartBeatTimer, disableHeartBeatTimer, killFrame, redirectFile, setCountPreRendered, - trackGoal, trackLink, trackPageView, trackRequest, trackSiteSearch, trackEvent, + trackGoal, trackLink, trackPageView, getNumTrackedPageViews, trackRequest, trackSiteSearch, trackEvent, setEcommerceView, addEcommerceItem, trackEcommerceOrder, trackEcommerceCartUpdate, deleteCookie, deleteCookies, offsetTop, offsetLeft, offsetHeight, offsetWidth, nodeType, defaultView, innerHTML, scrollLeft, scrollTop, currentStyle, getComputedStyle, querySelectorAll, splice, @@ -1037,8 +1037,8 @@ if (typeof JSON_PIWIK !== 'object' && typeof window.JSON === 'object' && window. /*global AnalyticsTracker:true */ /*members initialize */ /*global define */ +/*global console */ /*members amd */ -/*global console:true */ /*members error */ /*members log */ @@ -1168,7 +1168,9 @@ if (typeof window.Piwik !== 'object') { * @param message */ function logConsoleError(message) { - if (console !== undefined && console && console.error) { + // needed to write it this way for jslint + var consoleType = typeof console; + if (consoleType !== 'undefined' && console && console.error) { console.error(message); } } @@ -3186,7 +3188,13 @@ if (typeof window.Piwik !== 'object') { // Domain hash value domainHash, - configIdPageView; + configIdPageView, + + // we measure how many pageviews have been tracked so plugins can use it to eg detect if a + // pageview was already tracked or not + numTrackedPageviews = 0, + + configCookiesToDelete = ['id', 'ses', 'cvar', 'ref']; // Document title try { @@ -4025,11 +4033,10 @@ if (typeof window.Piwik !== 'object') { // Temporarily allow cookies just to delete the existing ones configCookiesDisabled = false; - var cookiesToDelete = ['id', 'ses', 'cvar', 'ref']; var index, cookieName; - for (index = 0; index < cookiesToDelete.length; index++) { - cookieName = getCookieName(cookiesToDelete[index]); + for (index = 0; index < configCookiesToDelete.length; index++) { + cookieName = getCookieName(configCookiesToDelete[index]); if (0 !== getCookie(cookieName)) { deleteCookie(cookieName, configCookiePath, configCookieDomain); } @@ -5523,9 +5530,6 @@ if (typeof window.Piwik !== 'object') { this.getDomains = function () { return configHostsAlias; }; - this.getConfigCookiePath = function () { - return configCookiePath; - }; this.getConfigIdPageView = function () { return configIdPageView; }; @@ -6254,7 +6258,59 @@ if (typeof window.Piwik !== 'object') { }; /** - * Set first-party cookie path + * Get first-party cookie domain + */ + this.getCookieDomain = function () { + return configCookieDomain; + }; + + /** + * Detect if cookies are enabled and supported by browser. + */ + this.hasCookies = function () { + return '1' === hasCookies(); + }; + + /** + * Set a first-party cookie for the duration of the session. + * + * @param string cookieName + * @param string cookieValue + * @param int msToExpire Defaults to session cookie timeout + */ + this.setSessionCookie = function (cookieName, cookieValue, msToExpire) { + if (!cookieName) { + throw new Error('Missing cookie name'); + } + + if (!isDefined(msToExpire)) { + msToExpire = configSessionCookieTimeout; + } + + configCookiesToDelete.push(cookieName); + + setCookie(getCookieName(cookieName), cookieValue, msToExpire, configCookiePath, configCookieDomain); + }; + + /** + * Get first-party cookie value. + * + * Returns null if cookies are disabled or if no cookie could be found for this name. + * + * @param string cookieName + */ + this.getCookie = function (cookieName) { + var cookieValue = getCookie(getCookieName(cookieName)); + + if (cookieValue === 0) { + return null; + } + + return cookieValue; + }; + + /** + * Set first-party cookie path. * * @param string domain */ @@ -6264,6 +6320,15 @@ if (typeof window.Piwik !== 'object') { }; /** + * Get first-party cookie path. + * + * @param string domain + */ + this.getCookiePath = function (path) { + return configCookiePath; + }; + + /** * Set visitor cookie timeout (in seconds) * Defaults to 13 months (timeout=33955200) * @@ -6284,6 +6349,13 @@ if (typeof window.Piwik !== 'object') { }; /** + * Get session cookie timeout (in seconds). + */ + this.getSessionCookieTimeout = function () { + return configSessionCookieTimeout; + }; + + /** * Set referral cookie timeout (in seconds). * Defaults to 6 months (15768000000) * @@ -6543,6 +6615,13 @@ if (typeof window.Piwik !== 'object') { }; /** + * Get the number of page views that have been tracked so far within the currently loaded page. + */ + this.getNumTrackedPageViews = function () { + return numTrackedPageviews; + }; + + /** * Log visit to this page * * @param string customTitle @@ -6558,6 +6637,7 @@ if (typeof window.Piwik !== 'object') { }); } else { trackCallback(function () { + numTrackedPageviews++; logPageView(customTitle, customData, callback); }); } @@ -6767,7 +6847,9 @@ if (typeof window.Piwik !== 'object') { var contentNodes = content.findContentNodes(); var contents = content.collectContent(contentNodes); - if (console !== undefined && console && console.log) { + // needed to write it this way for jslint + var consoleType = typeof console; + if (consoleType !== 'undefined' && console && console.log) { console.log(contents); } }; @@ -7277,7 +7359,9 @@ if (typeof window.Piwik !== 'object') { window.Piwik.addTracker(); } else { _paq = {push: function (args) { - if (console !== undefined && console && console.error) { + // needed to write it this way for jslint + var consoleType = typeof console; + if (consoleType !== 'undefined' && console && console.error) { console.error('_paq.push() was used but Piwik tracker was not initialized before the piwik.js file was loaded. Make sure to configure the tracker via _paq.push before loading piwik.js. Alternatively, you can create a tracker via Piwik.addTracker() manually and then use _paq.push but it may not fully work as tracker methods may not be executed in the correct order.', args); } }}; |