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
파일 보기 프로젝트 열기: piwik/piwik 1 사용 예제들

공개 메소드들

메소드 설명
__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.

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.

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.

isTimezoneSupportEnabled() 공개 메소드

Return true if Timezone support is enabled on server

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.