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.

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 string value.

getName()

Returns the name of the site.

Signature

  • It returns a string value.
  • 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 string value.
  • 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 int value.
  • 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 string value.

getCreationDate()

Returns the creation date of the site.

Signature

  • It returns a Date value.
  • 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 string value.
  • 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 string value.
  • 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 string value.
  • 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 string value.
  • 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 bool value.
  • 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 string value.
  • 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 string value.
  • 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 bool value.
  • 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: array — 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 string value.

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 string value.

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 string value.

getTypeFor()

Returns the type of the site with the specified ID.

Signature

  • It accepts the following parameter(s):

    • $idsite
  • It returns a string value.

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 string value.

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 string value.

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 string value.

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 string value.

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 string value.

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 string value.

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 string value.

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 string value.

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.