Site
Piwik\
Site
Provides access to individual site entity data (including name, URL, etc.).
Data Cache
Site data can be cached in order to avoid performing too many queries. If a method needs many site entities, it is more efficient to query all of what you need beforehand via the SitesManager API, then cache it using setSites() or setSitesFromArray().
Subsequent calls to new Site($id) will use the data in the cache instead of querying the database.
Examples
Basic usage
$site = new Site($idSite);
$name = $site->getName();
Without allocation
$name = Site::getNameFor($idSite);
Methods
The class defines the following methods:
__construct()— Constructor.setSites()— Sets the cached site data with an array that associates site IDs with individual site data.__toString()— Returns a string representation of the site this instance references.getName()— Returns the name of the site.getMainUrl()— Returns the main url of the site.getId()— Returns the id of the site.getType()ash; Returns the website type (by default"website", which means it is a single website).getCreationDate()— Returns the creation date of the site.getTimezone()— Returns the timezone of the size.getCurrency()— Returns the currency of the site.getExcludedIps()— Returns the excluded ips of the site.getExcludedQueryParameters()— Returns the excluded query parameters of the site.isEcommerceEnabled()— Returns whether ecommerce is enabled for the site.getSearchKeywordParameters()— Returns the site search keyword query parameters for the site.getSearchCategoryParameters()— Returns the site search category query parameters for the site.isSiteSearchEnabled()— Returns whether Site Search Tracking is enabled for the site.getCreatorLogin()— Returns the user that created this site.getIdSitesFromIdSitesString()— Checks the given string for valid site IDs and returns them as an array.clearCache()— Clears the site data cache.clearCacheForSite()— Clears the site data cache.getNameFor()— Returns the name of the site with the specified ID.getGroupFor()— Returns the group of the site with the specified ID.getTimezoneFor()— Returns the timezone of the site with the specified ID.getTypeFor()— Returns the type of the site with the specified ID.getCreationDateFor()— Returns the creation date of the site with the specified ID.getMainUrlFor()— Returns the url for the site with the specified ID.isEcommerceEnabledFor()— Returns whether the site with the specified ID is ecommerce enabled or not.isSiteSearchEnabledFor()— Returns whether the site with the specified ID is Site Search enabled.getCurrencyFor()— Returns the currency of the site with the specified ID.getCurrencySymbolFor()— Returns the currency of the site with the specified ID.getExcludedIpsFor()— Returns the excluded IP addresses of the site with the specified ID.getExcludedQueryParametersFor()— Returns the excluded query parameters for the site with the specified ID.getCreatorLoginFor()— Returns the user that created this site.
__construct()
Constructor.
Signature
- It accepts the following parameter(s):
$idsite(int) — The ID of the site we want data for.
- It throws one of the following exceptions:
Piwik\Exception\UnexpectedWebsiteFoundException
setSites()
Sets the cached site data with an array that associates site IDs with individual site data.
Signature
- It accepts the following parameter(s):
$sites(array) — The array of sites data. Indexed by site ID. eg, array('1' => array('name' => 'Site 1', ...), '2' => array('name' => 'Site 2', ...))`
- It does not return anything or a mixed result.
__toString()
Returns a string representation of the site this instance references.
Useful for debugging.
Signature
- It returns a
stringvalue.
getName()
Returns the name of the site.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getMainUrl()
Returns the main url of the site.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getId()
Returns the id of the site.
Signature
- It returns a
intvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getType()
Returns the website type (by default "website", which means it is a single website).
Signature
- It returns a
stringvalue.
getCreationDate()
Returns the creation date of the site.
Signature
- It returns a
Datevalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getTimezone()
Returns the timezone of the size.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getCurrency()
Returns the currency of the site.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getExcludedIps()
Returns the excluded ips of the site.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getExcludedQueryParameters()
Returns the excluded query parameters of the site.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
isEcommerceEnabled()
Returns whether ecommerce is enabled for the site.
Signature
- It returns a
boolvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getSearchKeywordParameters()
Returns the site search keyword query parameters for the site.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getSearchCategoryParameters()
Returns the site search category query parameters for the site.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
isSiteSearchEnabled()
Returns whether Site Search Tracking is enabled for the site.
Signature
- It returns a
boolvalue. - It throws one of the following exceptions:
Exception— if data for the site cannot be found.
getCreatorLogin()
Returns the user that created this site.
Signature
- Returns:
string|null— If null, the site was created before the creation user was tracked.
getIdSitesFromIdSitesString()
Checks the given string for valid site IDs and returns them as an array.
Signature
It accepts the following parameter(s):
$ids(string|array) — Comma separated idSite list, eg,'1,2,3,4'or an array of IDs, eg,array(1, 2, 3, 4).$_restrictSitesToLogin(bool|string) — Implementation detail. Used only when running as a scheduled task.
Returns:
Piwik\array<string>|Piwik\array<int>— An array of valid, unique integers.
clearCache()
Clears the site data cache.
See also setSites() and setSitesFromArray().
Signature
- It does not return anything or a mixed result.
clearCacheForSite()
Clears the site data cache.
See also setSites() and setSitesFromArray().
Signature
It accepts the following parameter(s):
$idSite
It does not return anything or a mixed result.
getNameFor()
Returns the name of the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getGroupFor()
Returns the group of the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getTimezoneFor()
Returns the timezone of the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getTypeFor()
Returns the type of the site with the specified ID.
Signature
It accepts the following parameter(s):
$idsite
It returns a
stringvalue.
getCreationDateFor()
Returns the creation date of the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getMainUrlFor()
Returns the url for the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
isEcommerceEnabledFor()
Returns whether the site with the specified ID is ecommerce enabled or not.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
isSiteSearchEnabledFor()
Returns whether the site with the specified ID is Site Search enabled.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getCurrencyFor()
Returns the currency of the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getCurrencySymbolFor()
Returns the currency of the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getExcludedIpsFor()
Returns the excluded IP addresses of the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getExcludedQueryParametersFor()
Returns the excluded query parameters for the site with the specified ID.
Signature
- It accepts the following parameter(s):
$idsite(int) — The site ID.
- It returns a
stringvalue.
getCreatorLoginFor()
Returns the user that created this site.
Signature
It accepts the following parameter(s):
$idsite(int) — The site ID.
Returns:
string|null— If null, the site was created before the creation user was tracked.