The code seen previously executes when a page or a frame being tracked loads in a browser. It contains all the logic that Piwik needs to track a visitor.
The first executable line in this code occurs when the variable pkBaseURL
is set. The tracking code determines whether the URL currently loaded is SSL or Non-SSL, and creates pkBaseURL
—the URL for your Piwik installation—with either a leading http://
or https://
. Once the URL to Piwik has been generated, the JavaScript code includes the piwik.js
file from your Piwik installation in the loaded page.
After the piwik.js
file has been delivered to the visitor's browser, a tracker object is created with the variable name of piwikTracker
. This object will be used to track all the actions that this visitor will perform on the site. The Piwik JavaScript function was loaded with the piwik.js
file and holds the getTracker
function, which creates the tracker object.