org.piwik
Class SimplePiwikTracker

java.lang.Object
  extended by org.piwik.SimplePiwikTracker
All Implemented Interfaces:
PiwikTracker

public class SimplePiwikTracker
extends Object
implements PiwikTracker

Piwik - Open source web analytics Client to record visits, page views, Goals, in a Piwik server. For more information, see http://piwik.org/docs/tracking-api/ released under BSD License http://www.opensource.org/licenses/bsd-license.php

Author:
Martin Fochler, Klaus Pfeiffer, Bernhard Friedreich

Field Summary
static int MAX_CUSTOM_VARIABLE_LENGTH
          Maximum length of a custom variable.
static int MAX_CUSTOM_VARIABLES
          Maximum number of custom variables.
static int VERSION
           
 
Constructor Summary
SimplePiwikTracker(int idSite, String apiUrl, javax.servlet.http.HttpServletRequest request)
          Builds a PiwikTracker object, used to track visits, pages and Goal conversions for a specific website, by using the Piwik Tracking API.
SimplePiwikTracker(String apiUrl)
           
 
Method Summary
 void clearCustomVariables()
          Resets all given custom variables.
 void clearPluginList()
          Resets all given browser plugins.
 String getCustomData()
          Getter.
 URL getDownloadTrackURL(String downloadurl)
          Builds the URL for the download tracking request.
 String getGeneralQuery()
          Returns the uery part for the url with all parameters from all given informations set to this tracker.
 URL getGoalTrackURL(String goal)
           
 URL getGoalTrackURL(String goal, String revenue)
           
 int getIdSite()
          Getter.
 String getIp()
          Getter.
 URL getLinkTrackURL(String linkurl)
           
 URL getPageTrackURL(String pagename)
          Builds the URL for the page tracking request.
 String getPageUrl()
          Getter.
 URL getUrlReferrer()
          Getter.
 String getVisitorCustomData()
           
 String getVisitorId()
          Returns the visitor id of this tracker object.
 void readRequestInfos(javax.servlet.http.HttpServletRequest request)
          Sets information to the tracker from the request.
 ResponseData sendRequest(URL destination)
          Sends the request to the PIWIK-Server.
 void setAcceptLanguage(Locale locale)
          Sets the language set in the browser request.
 void setAcceptLanguage(String language)
          Sets the language set in the browser request.
 void setApiurl(String apiurl)
          Sets the url of the piwik installation the tracker will track to.
 void setApiurl(URL apiurl)
          Sets the url of the piwik installation the tracker will track to.
 void setCustomData(String customData)
          Sets the custom data.
 void setDebugAppendUrl(String debugAppendUrl)
          Sets a string for debugging usage.
 void setForcedDatetime(Date forcedDatetime)
          Sets the time the request was send.
 void setIdSite(int idSite)
          Sets the site id.
 void setIp(String ip)
          Sets the ip from which the request was send.
 void setLocalTime(Date time)
          Sets local visitor time.
 void setLocalTime(String time)
          Sets local visitor time.
 int setPageCustomVariable(String name, String value)
          Sets page custom variables; ignoring fixed order (differs from PHP version).
 void setPageUrl(String pageUrl)
          Sets the Page URL.
 void setPlugin(BrowserPlugins plugin, boolean enabled)
          Adds a browser plugin to the list to detected plugins.
 boolean setRequestCookie(javax.servlet.http.Cookie requestCookie)
          Sets the piwik cookie of the requester.
 void setResolution(int width, int height)
          Sets the screen resolution of the browser which sends the request.
 void setTokenAuth(String tokenAuth)
          Sets the authentication string from the piwik installation for access of piwik data.
 void setUrlReferrer(String urlReferrer)
          Sets the referrer url of the request.
 void setUrlReferrer(URL urlReferrer)
          Sets the referrer url of the request.
 void setUserAgent(String userAgent)
          Sets the user agent identification of the requester.
 void setVisitorCustomData(String visitorCustomData)
           
 int setVisitorCustomVariable(String name, String value)
          Sets visitor custom variables; ignoring fixed order (differs from PHP version).
 void setVisitorId(String visitorId)
          Sets the id of the requester.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final int VERSION
See Also:
Constant Field Values

MAX_CUSTOM_VARIABLES

public static final int MAX_CUSTOM_VARIABLES
Maximum number of custom variables.

See Also:
Constant Field Values

MAX_CUSTOM_VARIABLE_LENGTH

public static final int MAX_CUSTOM_VARIABLE_LENGTH
Maximum length of a custom variable.

See Also:
Constant Field Values
Constructor Detail

SimplePiwikTracker

public SimplePiwikTracker(String apiUrl)
                   throws PiwikException
Parameters:
apiUrl -
Throws:
PiwikException

SimplePiwikTracker

public SimplePiwikTracker(int idSite,
                          String apiUrl,
                          javax.servlet.http.HttpServletRequest request)
                   throws PiwikException
Builds a PiwikTracker object, used to track visits, pages and Goal conversions for a specific website, by using the Piwik Tracking API.

Parameters:
idSite - Id of the site to be tracked
apiUrl - points to URL of the tracker server
request -
Throws:
PiwikException
Method Detail

getVisitorId

public final String getVisitorId()
Returns the visitor id of this tracker object.

Returns:
the visitor id as a String object

readRequestInfos

public final void readRequestInfos(javax.servlet.http.HttpServletRequest request)
                            throws PiwikException
Sets information to the tracker from the request. the information pageurl, urlreferer, useragend, ip, language and the piwik cookie will be read.

Parameters:
request -
Throws:
PiwikException - if the urls read could not be parsed to an url object

setAcceptLanguage

public final void setAcceptLanguage(String language)
Sets the language set in the browser request. This will be used to determine where the request comes from.

Parameters:
language - as a string object in ISO 639 code

setAcceptLanguage

public final void setAcceptLanguage(Locale locale)
Sets the language set in the browser request. This will be used to determine where the request comes from.

Parameters:
locale - as a locale object

setApiurl

public final void setApiurl(String apiurl)
                     throws PiwikException
Sets the url of the piwik installation the tracker will track to. The given string should be in the format of RFC2396. The string will be converted to an url with no other url as its context. If this is not wanted, create an own url object and use the equivalent function to this.

Parameters:
apiurl - as a string object
Throws:
PiwikException

setApiurl

public final void setApiurl(URL apiurl)
                     throws PiwikException
Sets the url of the piwik installation the tracker will track to.

Parameters:
apiurl - as a URL object
Throws:
PiwikException

setCustomData

public final void setCustomData(String customData)
Sets the custom data.

Parameters:
customData - the data as a string object

setDebugAppendUrl

public final void setDebugAppendUrl(String debugAppendUrl)
Sets a string for debugging usage. Please only call this function if debugging is wanted.

Parameters:
debugAppendUrl -

setForcedDatetime

public final void setForcedDatetime(Date forcedDatetime)
Sets the time the request was send.

Parameters:
forcedDatetime - the time as a date object

setIp

public final void setIp(String ip)
Sets the ip from which the request was send.

Parameters:
ip - the ip as a string object

setIdSite

public final void setIdSite(int idSite)
Sets the site id.

Parameters:
idSite -

setPageUrl

public final void setPageUrl(String pageUrl)
Sets the Page URL.

Parameters:
pageUrl -

setResolution

public final void setResolution(int width,
                                int height)
Sets the screen resolution of the browser which sends the request.

Parameters:
width - the screen width as an int value
height - the screen height as an int value

setRequestCookie

public final boolean setRequestCookie(javax.servlet.http.Cookie requestCookie)
Sets the piwik cookie of the requester. Therefor the name of the cookie has to be 'piwik_visitor'. All other cookies and null as parameter will reset the cookie.

Parameters:
requestCookie - the piwik cookie as cookie object
Returns:
true if the cookie was set otherwise false

setTokenAuth

public final void setTokenAuth(String tokenAuth)
Sets the authentication string from the piwik installation for access of piwik data.

Parameters:
tokenAuth - the token as a string object

setUrlReferrer

public final void setUrlReferrer(String urlReferrer)
                          throws PiwikException
Sets the referrer url of the request. This will be used to determine where the request comes from. The given string should be in the format of RFC2396. The string will be converted to an url with the apiurl as its context. This will makes relative urls to the apiurl possible. If this is not wanted, create an own url object and use the equivalent function to this.

Parameters:
urlReferrer - The referrer URL as a string object
Throws:
PiwikException

setUrlReferrer

public final void setUrlReferrer(URL urlReferrer)
Sets the referrer url of the request. This will be used to determine where the request comes from.

Parameters:
urlReferrer - the referrer URL as a URL object

setUserAgent

public final void setUserAgent(String userAgent)
Sets the user agent identification of the requester. This will be used to determine with which kind of client the request was send.

Parameters:
userAgent - the user agent identification as a string object

setVisitorId

public final void setVisitorId(String visitorId)
Sets the id of the requester. This will be used to determine if the requester is a returning visitor.

Parameters:
visitorId - the id of the visitor as a string object

setPageCustomVariable

public final int setPageCustomVariable(String name,
                                       String value)
                                throws PiwikException
Sets page custom variables; ignoring fixed order (differs from PHP version). still the order shouldn't change anyway.

Parameters:
name - Custom variable name
value - Custom variable value
Returns:
the count of the custom parameters
Throws:
PiwikException - when the maximum size of variables is reached or the name or the value is longer as the maximum variable length

setVisitorCustomVariable

public final int setVisitorCustomVariable(String name,
                                          String value)
                                   throws PiwikException
Sets visitor custom variables; ignoring fixed order (differs from PHP version). still the order shouldn't change anyway.

Parameters:
name - Custom variable name
value - Custom variable value
Returns:
the count of the custom parameters
Throws:
PiwikException - when the maximum size of variables is reached or the name or the value is longer as the maximum variable length

clearCustomVariables

public final void clearCustomVariables()
Resets all given custom variables.


setPlugin

public final void setPlugin(BrowserPlugins plugin,
                            boolean enabled)
Adds a browser plugin to the list to detected plugins. With the boolean flag is set whether the plugin is enabled or disabled.

Parameters:
plugin - the plugin which was detected
enabled - true is the plugin is enabled otherwise false

clearPluginList

public final void clearPluginList()
Resets all given browser plugins.


setLocalTime

public final void setLocalTime(String time)
                        throws PiwikException
Sets local visitor time.

Parameters:
time - the local time as a string object in the format HH:MM:SS
Throws:
PiwikException

setLocalTime

public final void setLocalTime(Date time)
Sets local visitor time. With null you can reset the time.

Parameters:
time - the local time as a date object

getGeneralQuery

public final String getGeneralQuery()
Returns the uery part for the url with all parameters from all given informations set to this tracker. This function is called in the defined URL for the tacking purpose.

Returns:
the query part for the URL as string object

getGoalTrackURL

public final URL getGoalTrackURL(String goal)
Specified by:
getGoalTrackURL in interface PiwikTracker
Parameters:
goal -
Returns:
URL

getGoalTrackURL

public final URL getGoalTrackURL(String goal,
                                 String revenue)
Specified by:
getGoalTrackURL in interface PiwikTracker
Parameters:
goal -
revenue -
Returns:
URL

getDownloadTrackURL

public final URL getDownloadTrackURL(String downloadurl)
Description copied from interface: PiwikTracker
Builds the URL for the download tracking request.

Specified by:
getDownloadTrackURL in interface PiwikTracker
Returns:
URl

getLinkTrackURL

public final URL getLinkTrackURL(String linkurl)
Specified by:
getLinkTrackURL in interface PiwikTracker

getPageTrackURL

public final URL getPageTrackURL(String pagename)
Description copied from interface: PiwikTracker
Builds the URL for the page tracking request.

Specified by:
getPageTrackURL in interface PiwikTracker
Returns:
URL

sendRequest

public final ResponseData sendRequest(URL destination)
                               throws PiwikException
Sends the request to the PIWIK-Server.

Parameters:
destination - the built request string.
Returns:
ResponseData
Throws:
PiwikException

getCustomData

public String getCustomData()
Getter.

Returns:
custom data

getIdSite

public int getIdSite()
Getter.

Returns:
site id

getPageUrl

public String getPageUrl()
Getter.

Returns:
page URL

getIp

public String getIp()
Getter.

Returns:
IP

getUrlReferrer

public URL getUrlReferrer()
Getter.

Returns:
URL Referrer

getVisitorCustomData

public String getVisitorCustomData()

setVisitorCustomData

public void setVisitorCustomData(String visitorCustomData)


Copyright © 2013. All Rights Reserved.