PHP Класс Piwik\Plugins\SitesManager\API

This API lets you create websites via "addSite", update existing websites via "updateSite" and delete websites via "deleteSite". When creating websites, it can be useful to access internal codes used by Piwik for currencies via "getCurrencyList", or timezones via "getTimezonesList". There are also many ways to request a list of websites: from the website ID via "getSiteFromId" or the site URL via "getSitesIdFromSiteUrl". Often, the most useful technique is to list all websites that are known to a current user, based on the token_auth, via "getSitesWithAdminAccess", "getSitesWithViewAccess" or "getSitesWithAtLeastViewAccess" (which returns both). Some methods will affect all websites globally: "setGlobalExcludedIps" will set the list of IPs to be excluded on all websites, "setGlobalExcludedQueryParameters" will set the list of URL parameters to remove from URLs for all websites. The existing values can be fetched via "getExcludedIpsGlobal" and "getExcludedQueryParametersGlobal". See also the documentation about Managing Websites in Piwik.
Наследование: extends Piwik\Plugin\API
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( SettingsProvider $provider, SettingsMetadata $settingsMetadata )
addSite ( string $siteName, array | string $urls = null, integer $ecommerce = null, null $siteSearch = null, string $searchKeywordParameters = null, string $searchCategoryParameters = null, string $excludedIps = null, null $excludedQueryParameters = null, string $timezone = null, string $currency = null, string $group = null, string $startDate = null, null | string $excludedUserAgents = null, integer $keepURLFragments = null, string $type = null, array | null $settingValues = null, boolean | null $excludeUnknownUrls = null ) : integer Add a website.
addSiteAliasUrls ( integer $idSite, array | string $urls ) : integer Add a list of alias Urls to the given idSite
deleteSite ( integer $idSite ) Delete a website from the database, given its Id. The method deletes the actual site as well as some associated data. However, it does not delete any logs or archives that belong to this website. You can delete logs and archives for a site manually as described in this FAQ: http://piwik.org/faq/how-to/faq_73/ .
getAllSites ( ) : array Returns all websites, requires Super User access
getAllSitesId ( ) : array Returns the list of all the website IDs registered.
getCurrencyList ( ) : array Returns the list of supported currencies
getCurrencySymbols ( ) : array( Returns the list of currency symbols
getDefaultCurrency ( ) : string Returns the default currency that will be set when creating a website through the API.
getDefaultTimezone ( ) : string Returns the default timezone that will be set when creating a website through the API.
getExcludedIpsGlobal ( ) : string Returns the list of IPs that are excluded from all websites
getExcludedQueryParametersGlobal ( ) : string Returns the list of URL query parameters that are excluded from all websites
getExcludedUserAgentsGlobal ( ) : string Returns the list of user agent substrings to look for when excluding visits for all websites. If a visitor's user agent string contains one of these substrings, their visits will not be included.
getImageTrackingCode ( integer $idSite, string $piwikUrl = '', $actionName = false, integer $idGoal = false, integer $revenue = false ) : string Returns image link tracking code for a given site with specified options.
getIpsForRange ( string $ipRange ) : array | false Get the start and end IP addresses for an IP address range
getJavascriptTag ( integer $idSite, string $piwikUrl = '', boolean $mergeSubdomains = false, boolean $groupPageTitlesByDomain = false, boolean $mergeAliasUrls = false, boolean $visitorCustomVariables = false, boolean $pageCustomVariables = false, boolean $customCampaignNameQueryParam = false, boolean $customCampaignKeywordParam = false, boolean $doNotTrack = false, boolean $disableCookies = false, boolean $trackNoScript = false ) : string Returns the javascript tag for the given idSite.
getKeepURLFragmentsGlobal ( ) : boolean Returns true if the default behavior is to keep URL fragments when tracking, false if otherwise.
getNumWebsitesToDisplayPerPage ( ) : integer Returns the number of websites to display per page.
getPatternMatchSites ( string $pattern, integer | false $limit = false ) : array Find websites matching the given pattern.
getSearchCategoryParametersGlobal ( ) : string
getSearchKeywordParametersGlobal ( ) : string
getSiteFromId ( integer $idSite ) : array Returns the website information : name, main_url
getSiteSettings ( $idSite )
getSiteUrlsFromId ( integer $idSite ) : array Returns the list of all URLs registered for the given idSite (main_url + alias URLs).
getSitesFromGroup ( string $group = '' ) : array Returns all websites belonging to the specified group
getSitesGroups ( ) : array Returns the list of website groups, including the empty group if no group were specified for some websites
getSitesIdFromSiteUrl ( string $url ) : array Returns the list of websites ID associated with a URL.
getSitesIdFromTimezones ( array $timezones ) : array Returns all websites with a timezone matching one the specified timezones
getSitesIdWithAdminAccess ( ) : array Returns the list of websites ID with the 'admin' access for the current user.
getSitesIdWithAtLeastViewAccess ( boolean $_restrictSitesToLogin = false ) : array Returns the list of websites ID with the 'view' or 'admin' access for the current user.
getSitesIdWithViewAccess ( ) : array Returns the list of websites ID with the 'view' access for the current user.
getSitesIdWithVisits ( boolean | integer $timestamp = false ) : array Returns the list of the website IDs that received some visits since the specified timestamp.
getSitesWithAdminAccess ( boolean $fetchAliasUrls = false, false | string $pattern = false, false | integer $limit = false ) : array Returns the list of websites with the 'admin' access for the current user.
getSitesWithAtLeastViewAccess ( boolean | integer $limit = false, boolean $_restrictSitesToLogin = false ) : array Returns the list of websites with the 'view' or 'admin' access for the current user.
getSitesWithViewAccess ( ) : array Returns the list of websites with the 'view' access for the current user.
getTimezonesList ( ) : array Returns the list of timezones supported.
getUniqueSiteTimezones ( ) : array Returns the list of unique timezones from all configured sites.
isSiteSpecificUserAgentExcludeEnabled ( ) : boolean Returns true if site-specific user agent exclusion has been enabled. If it hasn't, only the global user agent substrings (see @setGlobalExcludedUserAgents) will be used.
isTimezoneSupportEnabled ( ) : boolean Return true if Timezone support is enabled on server
renameGroup ( $oldGroupName, $newGroupName )
setDefaultCurrency ( string $defaultCurrency ) : boolean Sets the default currency that will be used when creating websites
setDefaultTimezone ( string $defaultTimezone ) : boolean Sets the default timezone that will be used when creating websites
setGlobalExcludedIps ( string $excludedIps ) : boolean Sets IPs to be excluded from all websites. IPs can contain wildcards.
setGlobalExcludedQueryParameters ( string $excludedQueryParameters ) : boolean Sets list of URL query parameters to be excluded on all websites.
setGlobalExcludedUserAgents ( string $excludedUserAgents ) Sets list of user agent substrings to look for when excluding visits. For more info,
setGlobalSearchParameters ( $searchKeywordParameters, $searchCategoryParameters ) : boolean Sets Site Search keyword/category parameter names, to be used on websites which have not specified these values Expects Comma separated list of query params names
setKeepURLFragmentsGlobal ( $enabled ) Sets whether the default behavior should be to keep URL fragments when tracking or not.
setSiteAliasUrls ( $idSite, $urls = [] ) : integer Set the list of alias Urls for the given idSite
setSiteSpecificUserAgentExcludeEnabled ( boolean $enabled ) Sets whether it should be allowed to exclude different user agents for different websites.
updateSite ( integer $idSite, string $siteName = null, string | array $urls = null, integer $ecommerce = null, null | integer $siteSearch = null, string $searchKeywordParameters = null, string $searchCategoryParameters = null, string $excludedIps = null, null | string $excludedQueryParameters = null, string $timezone = null, string $currency = null, string $group = null, string $startDate = null, null | string $excludedUserAgents = null, integer | null $keepURLFragments = null, string $type = null, array | null $settingValues = null, boolean | null $excludeUnknownUrls = null ) : boolean Update an existing website.
updateSiteCreatedTime ( $idSites, Date $minDate ) Updates the field ts_created for the specified websites.

Защищенные методы

Метод Описание
getNormalizedUrls ( $url )

Приватные методы

Метод Описание
checkAndReturnCommaSeparatedStringList ( $parameters )
checkAndReturnExcludedIps ( string $excludedIps ) : array Checks that the submitted IPs (comma separated list) are valid Returns the cleaned up IPs
checkAndReturnType ( $type )
checkName ( $siteName ) Check that the website name has a correct format.
checkValidCurrency ( $currency )
checkValidTimezone ( $timezone )
getModel ( )
getSitesFromIds ( array $idSites, boolean $limit = false ) : array Returns the list of websites from the ID array in parameters.
getSitesId ( )
getTimezonesListUTCOffsets ( )
isValidIp ( string $ip ) : boolean Tests if the IP is a valid IP, allowing wildcards, except in the first octet.
isValidUrl ( string $url ) : boolean Tests if the URL is a valid URL
postUpdateWebsite ( $idSite )
removeTrailingSlash ( string $url ) : string Remove the final slash in the URLs if found
saveMeasurableSettings ( $idSite, $idType, $settingValues )
setAndValidateMeasurableSettings ( $idSite, $idType, $settingValues )
setSettingValue ( $fieldName, $value, $settingValues )

Описание методов

__construct() публичный Метод

public __construct ( SettingsProvider $provider, SettingsMetadata $settingsMetadata )
$provider Piwik\Plugin\SettingsProvider
$settingsMetadata Piwik\Plugins\CorePluginsAdmin\SettingsMetadata

addSite() публичный Метод

Requires Super User access. The website is defined by a name and an array of URLs.
public addSite ( string $siteName, array | string $urls = null, integer $ecommerce = null, null $siteSearch = null, string $searchKeywordParameters = null, string $searchCategoryParameters = null, string $excludedIps = null, null $excludedQueryParameters = null, string $timezone = null, string $currency = null, string $group = null, string $startDate = null, null | string $excludedUserAgents = null, integer $keepURLFragments = null, string $type = null, array | null $settingValues = null, boolean | null $excludeUnknownUrls = null ) : integer
$siteName string Site name
$urls array | string The URLs array must contain at least one URL called the 'main_url' ; if several URLs are provided in the array, they will be recorded as Alias URLs for this website. When calling API via HTTP specify multiple URLs via `&urls[]=http...&urls[]=http...`.
$ecommerce integer Is Ecommerce Reporting enabled for this website?
$siteSearch null
$searchKeywordParameters string Comma separated list of search keyword parameter names
$searchCategoryParameters string Comma separated list of search category parameter names
$excludedIps string Comma separated list of IPs to exclude from the reports (allows wildcards)
$excludedQueryParameters null
$timezone string Timezone string, eg. 'Europe/London'
$currency string Currency, eg. 'EUR'
$group string Website group identifier
$startDate string Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format
$excludedUserAgents null | string
$keepURLFragments integer If 1, URL fragments will be kept when tracking. If 2, they will be removed. If 0, the default global behavior will be used.
$type string The website type, defaults to "website" if not set.
$settingValues array | null JSON serialized settings eg {settingName: settingValue, ...}
$excludeUnknownUrls boolean | null Track only URL matching one of website URLs
Результат integer the website ID created

addSiteAliasUrls() публичный Метод

If some URLs given in parameter are already recorded as alias URLs for this website, they won't be duplicated. The 'main_url' of the website won't be affected by this method.
public addSiteAliasUrls ( integer $idSite, array | string $urls ) : integer
$idSite integer
$urls array | string When calling API via HTTP specify multiple URLs via `&urls[]=http...&urls[]=http...`.
Результат integer the number of inserted URLs

deleteSite() публичный Метод

Requires Super User access.
public deleteSite ( integer $idSite )
$idSite integer

getAllSites() публичный Метод

Returns all websites, requires Super User access
public getAllSites ( ) : array
Результат array The list of websites, indexed by idsite

getAllSitesId() публичный Метод

Requires Super User access.
public getAllSitesId ( ) : array
Результат array The list of website IDs

getCurrencyList() публичный Метод

Returns the list of supported currencies
См. также: getCurrencySymbols()
public getCurrencyList ( ) : array
Результат array ( currencyId => currencyName)

getCurrencySymbols() публичный Метод

Returns the list of currency symbols
См. также: getCurrencyList()
public getCurrencySymbols ( ) : array(
Результат array(

getDefaultCurrency() публичный Метод

Returns the default currency that will be set when creating a website through the API.
public getDefaultCurrency ( ) : string
Результат string Currency ID eg. 'USD'

getDefaultTimezone() публичный Метод

Via the UI, if the default timezone is not UTC, it will be pre-selected in the drop down
public getDefaultTimezone ( ) : string
Результат string Timezone eg. UTC+7 or Europe/Paris

getExcludedIpsGlobal() публичный Метод

Returns the list of IPs that are excluded from all websites
public getExcludedIpsGlobal ( ) : string
Результат string Comma separated list of IPs

getExcludedQueryParametersGlobal() публичный Метод

Returns the list of URL query parameters that are excluded from all websites
public getExcludedQueryParametersGlobal ( ) : string
Результат string Comma separated list of URL parameters

getExcludedUserAgentsGlobal() публичный Метод

Returns the list of user agent substrings to look for when excluding visits for all websites. If a visitor's user agent string contains one of these substrings, their visits will not be included.
public getExcludedUserAgentsGlobal ( ) : string
Результат string Comma separated list of strings.

getImageTrackingCode() публичный Метод

Returns image link tracking code for a given site with specified options.
public getImageTrackingCode ( integer $idSite, string $piwikUrl = '', $actionName = false, integer $idGoal = false, integer $revenue = false ) : string
$idSite integer The ID to generate tracking code for.
$piwikUrl string The domain and URL path to the Piwik installation.
$idGoal integer An ID for a goal to trigger a conversion for.
$revenue integer The revenue of the goal conversion. Only used if $idGoal is supplied.
Результат string The HTML tracking code.

getIpsForRange() публичный Метод

Get the start and end IP addresses for an IP address range
public getIpsForRange ( string $ipRange ) : array | false
$ipRange string IP address range in presentation format
Результат array | false Array( low, high ) IP addresses in presentation format; or false if error

getJavascriptTag() публичный Метод

This tag must be included on every page to be tracked by Piwik
public getJavascriptTag ( integer $idSite, string $piwikUrl = '', boolean $mergeSubdomains = false, boolean $groupPageTitlesByDomain = false, boolean $mergeAliasUrls = false, boolean $visitorCustomVariables = false, boolean $pageCustomVariables = false, boolean $customCampaignNameQueryParam = false, boolean $customCampaignKeywordParam = false, boolean $doNotTrack = false, boolean $disableCookies = false, boolean $trackNoScript = false ) : string
$idSite integer
$piwikUrl string
$mergeSubdomains boolean
$groupPageTitlesByDomain boolean
$mergeAliasUrls boolean
$visitorCustomVariables boolean
$pageCustomVariables boolean
$customCampaignNameQueryParam boolean
$customCampaignKeywordParam boolean
$doNotTrack boolean
$disableCookies boolean
$trackNoScript boolean
Результат string The Javascript tag ready to be included on the HTML pages

getKeepURLFragmentsGlobal() публичный Метод

Returns true if the default behavior is to keep URL fragments when tracking, false if otherwise.
public getKeepURLFragmentsGlobal ( ) : boolean
Результат boolean

getNormalizedUrls() защищенный Метод

protected getNormalizedUrls ( $url )

getNumWebsitesToDisplayPerPage() публичный Метод

For example this is used in the All Websites Dashboard, in the Website Selector etc. If multiple websites are shown somewhere, one should request this method to detect how many websites should be shown per page when using paging. To use paging is always recommended since some installations have thousands of websites.
public getNumWebsitesToDisplayPerPage ( ) : integer
Результат integer

getPatternMatchSites() публичный Метод

Any website will be returned that matches the pattern in the name, URL or group. To limit the number of returned sites you can either specify filter_limit as usual or limit which is faster.
public getPatternMatchSites ( string $pattern, integer | false $limit = false ) : array
$pattern string
$limit integer | false
Результат array

getSearchCategoryParametersGlobal() публичный Метод

public getSearchCategoryParametersGlobal ( ) : string
Результат string Comma separated list of URL parameters

getSearchKeywordParametersGlobal() публичный Метод

public getSearchKeywordParametersGlobal ( ) : string
Результат string Comma separated list of URL parameters

getSiteFromId() публичный Метод

Returns the website information : name, main_url
public getSiteFromId ( integer $idSite ) : array
$idSite integer
Результат array

getSiteSettings() публичный Метод

public getSiteSettings ( $idSite )

getSiteUrlsFromId() публичный Метод

Returns the list of all URLs registered for the given idSite (main_url + alias URLs).
public getSiteUrlsFromId ( integer $idSite ) : array
$idSite integer
Результат array list of URLs

getSitesFromGroup() публичный Метод

Returns all websites belonging to the specified group
public getSitesFromGroup ( string $group = '' ) : array
$group string Group name
Результат array of sites

getSitesGroups() публичный Метод

Returns the list of website groups, including the empty group if no group were specified for some websites
public getSitesGroups ( ) : array
Результат array of group names strings

getSitesIdFromSiteUrl() публичный Метод

Returns the list of websites ID associated with a URL.
public getSitesIdFromSiteUrl ( string $url ) : array
$url string
Результат array list of websites ID

getSitesIdFromTimezones() публичный Метод

Returns all websites with a timezone matching one the specified timezones
public getSitesIdFromTimezones ( array $timezones ) : array
$timezones array
Результат array

getSitesIdWithAdminAccess() публичный Метод

For the superUser it returns all the websites in the database.
public getSitesIdWithAdminAccess ( ) : array
Результат array list of websites ID

getSitesIdWithAtLeastViewAccess() публичный Метод

For the superUser it returns all the websites in the database.
public getSitesIdWithAtLeastViewAccess ( boolean $_restrictSitesToLogin = false ) : array
$_restrictSitesToLogin boolean
Результат array list of websites ID

getSitesIdWithViewAccess() публичный Метод

For the superUser it doesn't return any result because the superUser has admin access on all the websites (use getSitesIdWithAtLeastViewAccess() instead).
public getSitesIdWithViewAccess ( ) : array
Результат array list of websites ID

getSitesIdWithVisits() публичный Метод

Requires Super User access.
Устаревший: since 2.15 This method will be removed in Piwik 3.0, there is no replacement.
public getSitesIdWithVisits ( boolean | integer $timestamp = false ) : array
$timestamp boolean | integer
Результат array The list of website IDs

getSitesWithAdminAccess() публичный Метод

For the superUser it returns all the websites in the database.
public getSitesWithAdminAccess ( boolean $fetchAliasUrls = false, false | string $pattern = false, false | integer $limit = false ) : array
$fetchAliasUrls boolean
$pattern false | string
$limit false | integer
Результат array for each site, an array of information (idsite, name, main_url, etc.)

getSitesWithAtLeastViewAccess() публичный Метод

For the superUser it returns all the websites in the database.
public getSitesWithAtLeastViewAccess ( boolean | integer $limit = false, boolean $_restrictSitesToLogin = false ) : array
$limit boolean | integer Specify max number of sites to return
$_restrictSitesToLogin boolean Hack necessary when running scheduled tasks, where "Super User" is forced, but sometimes not desired, see #3017
Результат array array for each site, an array of information (idsite, name, main_url, etc.)

getSitesWithViewAccess() публичный Метод

For the superUser it doesn't return any result because the superUser has admin access on all the websites (use getSitesWithAtLeastViewAccess() instead).
public getSitesWithViewAccess ( ) : array
Результат array for each site, an array of information (idsite, name, main_url, etc.)

getTimezonesList() публичный Метод

Used for addSite and updateSite
public getTimezonesList ( ) : array
Результат array of timezone strings

getUniqueSiteTimezones() публичный Метод

Returns the list of unique timezones from all configured sites.
public getUniqueSiteTimezones ( ) : array
Результат array ( string )

isSiteSpecificUserAgentExcludeEnabled() публичный Метод

Returns true if site-specific user agent exclusion has been enabled. If it hasn't, only the global user agent substrings (see @setGlobalExcludedUserAgents) will be used.
public isSiteSpecificUserAgentExcludeEnabled ( ) : boolean
Результат boolean

isTimezoneSupportEnabled() публичный Метод

Return true if Timezone support is enabled on server
public isTimezoneSupportEnabled ( ) : boolean
Результат boolean

renameGroup() публичный Метод

public renameGroup ( $oldGroupName, $newGroupName )

setDefaultCurrency() публичный Метод

Sets the default currency that will be used when creating websites
public setDefaultCurrency ( string $defaultCurrency ) : boolean
$defaultCurrency string Currency code, eg. 'USD'
Результат boolean

setDefaultTimezone() публичный Метод

Sets the default timezone that will be used when creating websites
public setDefaultTimezone ( string $defaultTimezone ) : boolean
$defaultTimezone string Timezone string eg. Europe/Paris or UTC+8
Результат boolean

setGlobalExcludedIps() публичный Метод

Will also apply to websites created in the future.
public setGlobalExcludedIps ( string $excludedIps ) : boolean
$excludedIps string Comma separated list of IPs to exclude from being tracked (allows wildcards)
Результат boolean

setGlobalExcludedQueryParameters() публичный Метод

Will also apply to websites created in the future.
public setGlobalExcludedQueryParameters ( string $excludedQueryParameters ) : boolean
$excludedQueryParameters string Comma separated list of URL query parameters to exclude from URLs
Результат boolean

setGlobalExcludedUserAgents() публичный Метод

Sets list of user agent substrings to look for when excluding visits. For more info,
public setGlobalExcludedUserAgents ( string $excludedUserAgents )
$excludedUserAgents string Comma separated list of strings. Each element is trimmed, and empty strings are removed.

setGlobalSearchParameters() публичный Метод

Sets Site Search keyword/category parameter names, to be used on websites which have not specified these values Expects Comma separated list of query params names
public setGlobalSearchParameters ( $searchKeywordParameters, $searchCategoryParameters ) : boolean
Результат boolean

setKeepURLFragmentsGlobal() публичный Метод

Sets whether the default behavior should be to keep URL fragments when tracking or not.
public setKeepURLFragmentsGlobal ( $enabled )
$enabled bool If true, the default behavior will be to keep URL fragments when tracking. If false, the default behavior will be to remove them.

setSiteAliasUrls() публичный Метод

Completely overwrites the current list of URLs with the provided list. The 'main_url' of the website won't be affected by this method.
public setSiteAliasUrls ( $idSite, $urls = [] ) : integer
Результат integer the number of inserted URLs

setSiteSpecificUserAgentExcludeEnabled() публичный Метод

Sets whether it should be allowed to exclude different user agents for different websites.

updateSite() публичный Метод

If only one URL is specified then only the main url will be updated. If several URLs are specified, both the main URL and the alias URLs will be updated.
public updateSite ( integer $idSite, string $siteName = null, string | array $urls = null, integer $ecommerce = null, null | integer $siteSearch = null, string $searchKeywordParameters = null, string $searchCategoryParameters = null, string $excludedIps = null, null | string $excludedQueryParameters = null, string $timezone = null, string $currency = null, string $group = null, string $startDate = null, null | string $excludedUserAgents = null, integer | null $keepURLFragments = null, string $type = null, array | null $settingValues = null, boolean | null $excludeUnknownUrls = null ) : boolean
$idSite integer website ID defining the website to edit
$siteName string website name
$urls string | array the website URLs When calling API via HTTP specify multiple URLs via `&urls[]=http...&urls[]=http...`.
$ecommerce integer Whether Ecommerce is enabled, 0 or 1
$siteSearch null | integer Whether site search is enabled, 0 or 1
$searchKeywordParameters string Comma separated list of search keyword parameter names
$searchCategoryParameters string Comma separated list of search category parameter names
$excludedIps string Comma separated list of IPs to exclude from being tracked (allows wildcards)
$excludedQueryParameters null | string
$timezone string Timezone
$currency string Currency code
$group string Group name where this website belongs
$startDate string Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format
$excludedUserAgents null | string
$keepURLFragments integer | null If 1, URL fragments will be kept when tracking. If 2, they will be removed. If 0, the default global behavior will be used.
$type string The Website type, default value is "website"
$settingValues array | null JSON serialized settings eg {settingName: settingValue, ...}
$excludeUnknownUrls boolean | null Track only URL matching one of website URLs
Результат boolean true on success

updateSiteCreatedTime() публичный Метод

Updates the field ts_created for the specified websites.
public updateSiteCreatedTime ( $idSites, Date $minDate )
$idSites int Id Site to update ts_created
$minDate Piwik\Date Date to set as creation date. To play it safe it will subtract one more day.