diff options
author | diosmosis <benaka.moorthi@gmail.com> | 2013-02-10 09:24:18 +0400 |
---|---|---|
committer | diosmosis <benaka.moorthi@gmail.com> | 2013-02-10 09:24:18 +0400 |
commit | ac59017af362e0f1069722df1677f31ac49a3707 (patch) | |
tree | 28517a9a1a7def172e6e44011b74e856c258c23e /plugins | |
parent | 2ee4124dd67187bb04b17b872a555bb10e2ac712 (diff) |
Fixes #3232, add ability to discard URL fragments when tracking for all websites or for just some websites.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/SitesManager/API.php | 75 | ||||
-rw-r--r-- | plugins/SitesManager/Controller.php | 22 | ||||
-rw-r--r-- | plugins/SitesManager/SitesManager.php | 25 | ||||
-rw-r--r-- | plugins/SitesManager/templates/SitesManager.js | 17 | ||||
-rw-r--r-- | plugins/SitesManager/templates/SitesManager.tpl | 21 |
5 files changed, 149 insertions, 11 deletions
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index 0575a265cb..4b15bc8740 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -50,6 +50,7 @@ class Piwik_SitesManager_API const OPTION_SEARCH_CATEGORY_QUERY_PARAMETERS_GLOBAL = 'SitesManager_SearchCategoryParameters'; const OPTION_EXCLUDED_USER_AGENTS_GLOBAL = 'SitesManager_ExcludedUserAgentsGlobal'; const OPTION_SITE_SPECIFIC_USER_AGENT_EXCLUDE_ENABLE = 'SitesManager_EnableSiteSpecificUserAgentExclude'; + const OPTION_KEEP_URL_FRAGMENTS_GLOBAL = 'SitesManager_KeepURLFragmentsGlobal'; /** * Returns the javascript tag for the given idSite. @@ -448,7 +449,9 @@ class Piwik_SitesManager_API * @param string Currency, eg. 'EUR' * @param string Website group identifier * @param string Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format - * + * @param int $keepURLFragments If 1, URL fragments will be kept when tracking. If 2, they + * will be removed. If 0, the default global behavior will be used. + * @see getKeepURLFragmentsGlobal. * * @return int the website ID created */ @@ -464,7 +467,8 @@ class Piwik_SitesManager_API $currency = null, $group = null, $startDate = null, - $excludedUserAgents = null ) + $excludedUserAgents = null, + $keepURLFragments = 0 ) { Piwik::checkUserIsSuperUser(); @@ -474,6 +478,9 @@ class Piwik_SitesManager_API $this->checkAtLeastOneUrl($urls); $siteSearch = $this->checkSiteSearch($siteSearch); list($searchKeywordParameters, $searchCategoryParameters ) = $this->checkSiteSearchParameters($searchKeywordParameters, $searchCategoryParameters); + + $keepURLFragments = (int)$keepURLFragments; + self::checkKeepURLFragmentsValue($keepURLFragments); $timezone = trim($timezone); if(empty($timezone)) @@ -501,6 +508,7 @@ class Piwik_SitesManager_API $bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps); $bind['excluded_parameters'] = $this->checkAndReturnCommaSeparatedStringList($excludedQueryParameters); $bind['excluded_user_agents'] = $this->checkAndReturnCommaSeparatedStringList($excludedUserAgents); + $bind['keep_url_fragment'] = $keepURLFragments; $bind['timezone'] = $timezone; $bind['currency'] = $currency; $bind['ecommerce'] = (int)$ecommerce; @@ -820,6 +828,37 @@ class Piwik_SitesManager_API } /** + * Returns true if the default behavior is to keep URL fragments when tracking, + * false if otherwise. + * + * @return bool + */ + public function getKeepURLFragmentsGlobal() + { + Piwik::checkUserHasSomeViewAccess(); + return (bool)Piwik_GetOption(self::OPTION_KEEP_URL_FRAGMENTS_GLOBAL); + } + + /** + * Sets whether the default behavior should be to keep URL fragments when + * tracking or not. + * + * @param $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. + */ + public function setKeepURLFragmentsGlobal( $enabled ) + { + Piwik::checkUserIsSuperUser(); + + // update option + Piwik_SetOption(self::OPTION_KEEP_URL_FRAGMENTS_GLOBAL, $enabled); + + // make sure tracker cache will reflect change + Piwik_Common::deleteTrackerCache(); + } + + /** * Sets list of URL query parameters to be excluded on all websites. * Will also apply to websites created in the future. * @@ -924,6 +963,10 @@ class Piwik_SitesManager_API * @param string $currency Currency code * @param string $group Group name where this website belongs * @param string $startDate Date at which the statistics for this website will start. Defaults to today's date in YYYY-MM-DD format + * @param int|null $keepURLFragments If 1, URL fragments will be kept when tracking. If 2, they + * will be removed. If 0, the default global behavior will be used. + * @see getKeepURLFragmentsGlobal. If null, the existing value will + * not be modified. * * @throws Exception * @return bool true on success @@ -941,7 +984,8 @@ class Piwik_SitesManager_API $currency = null, $group = null, $startDate = null, - $excludedUserAgents = null) + $excludedUserAgents = null, + $keepURLFragments = null) { Piwik::checkUserHasAdminAccess($idSite); @@ -992,6 +1036,14 @@ class Piwik_SitesManager_API $bind['excluded_ips'] = $this->checkAndReturnExcludedIps($excludedIps); $bind['excluded_parameters'] = $this->checkAndReturnCommaSeparatedStringList($excludedQueryParameters); $bind['excluded_user_agents'] = $this->checkAndReturnCommaSeparatedStringList($excludedUserAgents); + + if (!is_null($keepURLFragments)) + { + $keepURLFragments = (int)$keepURLFragments; + self::checkKeepURLFragmentsValue($keepURLFragments); + + $bind['keep_url_fragment'] = $keepURLFragments; + } $bind['sitesearch'] = $this->checkSiteSearch($siteSearch); list($searchKeywordParameters, $searchCategoryParameters ) = $this->checkSiteSearchParameters($searchKeywordParameters, $searchCategoryParameters); @@ -1339,4 +1391,21 @@ class Piwik_SitesManager_API $bind) ; return $sites; } + + /** + * Utility function that throws if a value is not valid for the 'keep_url_fragment' + * column of the piwik_site table. + * + * @param int $keepURLFragments + * @throws Exception + */ + private static function checkKeepURLFragmentsValue( $keepURLFragments ) + { + if ($keepURLFragments < 0 + || $keepURLFragments > 2) // make sure value is between 0 & 2 + { + throw new Exception("Error in SitesManager.updateSite: keepURLFragments must be between 0 & 2" + + " (actual value: $keepURLFragments)."); + } + } } diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index 7c3a1653f8..0766fc835c 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -67,6 +67,8 @@ class Piwik_SitesManager_Controller extends Piwik_Controller_Admin $view->allowSiteSpecificUserAgentExclude = Piwik_SitesManager_API::getInstance()->isSiteSpecificUserAgentExcludeEnabled(); + $view->globalKeepURLFragments = Piwik_SitesManager_API::getInstance()->getKeepURLFragmentsGlobal(); + $view->currentIpAddress = Piwik_IP::getIpFromHeader(); $view->showAddSite = (boolean) Piwik_Common::getRequestVar('showaddsite', false); @@ -93,14 +95,18 @@ class Piwik_SitesManager_Controller extends Piwik_Controller_Admin $searchKeywordParameters = Piwik_Common::getRequestVar('searchKeywordParameters', $default = ""); $searchCategoryParameters = Piwik_Common::getRequestVar('searchCategoryParameters', $default = ""); $enableSiteUserAgentExclude = Piwik_Common::getRequestVar('enableSiteUserAgentExclude', $default = 0); - Piwik_SitesManager_API::getInstance()->setDefaultTimezone($timezone); - Piwik_SitesManager_API::getInstance()->setDefaultCurrency($currency); - Piwik_SitesManager_API::getInstance()->setGlobalExcludedQueryParameters($excludedQueryParameters); - Piwik_SitesManager_API::getInstance()->setGlobalExcludedIps($excludedIps); - Piwik_SitesManager_API::getInstance()->setGlobalExcludedUserAgents($excludedUserAgents); - Piwik_SitesManager_API::getInstance()->setGlobalSearchParameters($searchKeywordParameters, $searchCategoryParameters); - Piwik_SitesManager_API::getInstance()->setSiteSpecificUserAgentExcludeEnabled( - $enableSiteUserAgentExclude == 1); + $keepURLFragments = Piwik_Common::getRequestVar('keepURLFragments', $default = 0); + + $api = Piwik_SitesManager_API::getInstance(); + $api->setDefaultTimezone($timezone); + $api->setDefaultCurrency($currency); + $api->setGlobalExcludedQueryParameters($excludedQueryParameters); + $api->setGlobalExcludedIps($excludedIps); + $api->setGlobalExcludedUserAgents($excludedUserAgents); + $api->setGlobalSearchParameters($searchKeywordParameters, $searchCategoryParameters); + $api->setSiteSpecificUserAgentExcludeEnabled($enableSiteUserAgentExclude == 1); + $api->setKeepURLFragmentsGlobal($keepURLFragments); + $toReturn = $response->getResponse(); } catch(Exception $e ) { $toReturn = $response->getResponseException( $e ); diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index d86b50025c..939b7116b7 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -15,6 +15,10 @@ */ class Piwik_SitesManager extends Piwik_Plugin { + const KEEP_URL_FRAGMENT_USE_DEFAULT = 0; + const KEEP_URL_FRAGMENT_YES = 1; + const KEEP_URL_FRAGMENT_NO = 2; + public function getInformation() { $info = array( @@ -86,10 +90,31 @@ class Piwik_SitesManager extends Piwik_Plugin $array['excluded_ips'] = $this->getTrackerExcludedIps($website); $array['excluded_parameters'] = self::getTrackerExcludedQueryParameters($website); $array['excluded_user_agents'] = self::getExcludedUserAgents($website); + $array['keep_url_fragment'] = self::shouldKeepURLFragmentsFor($website); $array['sitesearch'] = $website['sitesearch']; $array['sitesearch_keyword_parameters'] = $this->getTrackerSearchKeywordParameters($website); $array['sitesearch_category_parameters'] = $this->getTrackerSearchCategoryParameters($website); } + + /** + * Returns whether we should keep URL fragments for a specific site. + * + * @param array $site DB data for the site. + * @return bool + */ + private static function shouldKeepURLFragmentsFor( $site ) + { + if ($site['keep_url_fragment'] == self::KEEP_URL_FRAGMENT_YES) + { + return true; + } + else if ($site['keep_url_fragment'] == self::KEEP_URL_FRAGMENT_NO) + { + return false; + } + + return Piwik_SitesManager_API::getInstance()->getKeepURLFragmentsGlobal(); + } private function getTrackerSearchKeywordParameters($website) { diff --git a/plugins/SitesManager/templates/SitesManager.js b/plugins/SitesManager/templates/SitesManager.js index 09d825f7f7..c53ec58009 100644 --- a/plugins/SitesManager/templates/SitesManager.js +++ b/plugins/SitesManager/templates/SitesManager.js @@ -5,6 +5,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ +// NOTE: if you cannot find the definition of a variable here, look in SitesManager.tpl function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurrency ) { var timezones = _timezones; @@ -41,6 +42,7 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre excludedQueryParameters = piwikHelper.getApiFormatTextarea(excludedQueryParameters); var excludedUserAgents = $(row).find('textarea#excludedUserAgents').val(); excludedUserAgents = piwikHelper.getApiFormatTextarea(excludedUserAgents); + var keepURLFragments = $('#keepURLFragmentSelect', row).val(); var ecommerce = $(row).find('#ecommerce option:selected').val(); var sitesearch = $(row).find('#sitesearch option:selected').val(); var searchKeywordParameters = $('input#searchKeywordParameters').val(); @@ -60,6 +62,7 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre excludedIps: excludedIps, excludedQueryParameters: excludedQueryParameters, excludedUserAgents: excludedUserAgents, + keepURLFragments: keepURLFragments, siteSearch: sitesearch, searchKeywordParameters: searchKeywordParameters, searchCategoryParameters: searchCategoryParameters, @@ -82,6 +85,7 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre excludedQueryParameters = piwikHelper.getApiFormatTextarea(excludedQueryParameters); var excludedUserAgents = $(row).find('textarea#excludedUserAgents').val(); excludedUserAgents = piwikHelper.getApiFormatTextarea(excludedUserAgents); + var keepURLFragments = $('#keepURLFragmentSelect', row).val(); var timezone = $(row).find('#timezones option:selected').val(); var currency = $(row).find('#currencies option:selected').val(); var ecommerce = $(row).find('#ecommerce option:selected').val(); @@ -104,6 +108,7 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre excludedIps: excludedIps, excludedQueryParameters: excludedQueryParameters, excludedUserAgents: excludedUserAgents, + keepURLFragments: keepURLFragments, siteSearch: sitesearch, searchKeywordParameters: searchKeywordParameters, searchCategoryParameters: searchCategoryParameters, @@ -124,6 +129,7 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre excludedQueryParameters = piwikHelper.getApiFormatTextarea(excludedQueryParameters); var globalExcludedUserAgents = $('textarea#globalExcludedUserAgents').val(); globalExcludedUserAgents = piwikHelper.getApiFormatTextarea(globalExcludedUserAgents); + var globalKeepURLFragments = $('#globalKeepURLFragments').is(':checked') ? 1 : 0; var searchKeywordParameters = $('input#globalSearchKeywordParameters').val(); var searchCategoryParameters = $('input#globalSearchCategoryParameters').val(); var enableSiteUserAgentExclude = $('input#enableSiteUserAgentExclude').is(':checked') ? 1 : 0; @@ -140,6 +146,7 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre excludedIps: excludedIps, excludedQueryParameters: excludedQueryParameters, excludedUserAgents: globalExcludedUserAgents, + keepURLFragments: globalKeepURLFragments, enableSiteUserAgentExclude: enableSiteUserAgentExclude, searchKeywordParameters: searchKeywordParameters, searchCategoryParameters: searchCategoryParameters @@ -165,6 +172,7 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre <td><textarea cols="20" rows="4" id="excludedIps"></textarea><br />'+excludedIpHelp+'</td>\ <td><textarea cols="20" rows="4" id="excludedQueryParameters"></textarea><br />'+excludedQueryParametersHelp+'</td>\ <td><textarea cols="20" rows="4" id="excludedUserAgents"></textarea><br />'+excludedUserAgentsHelp+'</td>\ + <td>'+keepURLFragmentSelectHTML+'</td>\ <td>'+getSitesearchSelector(false)+'</td>\ <td>'+getTimezoneSelector(defaultTimezone)+'<br />' + timezoneHelp + '</td>\ <td>'+getCurrencySelector(defaultCurrency)+'<br />' + currencyHelp + '</td>\ @@ -264,6 +272,15 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre contentBefore.replace(/<br *\/? *>/gi,"\n")+'</textarea><br />'+excludedUserAgentsHelp; $(n).html(contentAfter); } + else if (idName == 'keepURLFragments') + { + $(n).html(keepURLFragmentSelectHTML) + // find the option to select by the option text and select it + .find('option').each(function() { + this.selected = this.text == contentBefore + || (this.value == 0 && contentBefore == '-'); + }); + } else if(idName == 'timezone') { var contentAfter = getTimezoneSelector(contentBefore); diff --git a/plugins/SitesManager/templates/SitesManager.tpl b/plugins/SitesManager/templates/SitesManager.tpl index 2c108e0210..89c646f94f 100644 --- a/plugins/SitesManager/templates/SitesManager.tpl +++ b/plugins/SitesManager/templates/SitesManager.tpl @@ -42,6 +42,14 @@ var aliasUrlsHelp = '{'SitesManager_AliasUrlHelp'|translate|inlineHelp|escape:ja {'SitesManager_GlobalListExcludedUserAgents_Desc'|translate} {'SitesManager_GlobalExcludedUserAgentHelp2'|translate} {/capture} {assign var=excludedUserAgentsHelp value=$excludedUserAgentsHelp|inlineHelp} + +{capture assign=keepURLFragmentSelectHTML} + <select id="keepURLFragmentSelect"> + <option value="0">{'General_Default'|translate}</option> + <option value="1">{'General_Yes'|translate}</option> + <option value="2">{'General_No'|translate}</option> + </select> +{/capture} var excludedQueryParametersHelp = '{$excludedQueryParametersHelp|escape:javascript}'; var excludedUserAgentsHelp = '{$excludedUserAgentsHelp|escape:javascript}'; var timezoneHelp = '{$timezoneHelpPlain|inlineHelp|escape:javascript}'; @@ -58,6 +66,7 @@ var sitesearchDisabled = '{'SitesManager_DisableSiteSearch'|translate|escape:jav var searchKeywordHelp = '{$searchKeywordHelp|escape:javascript}'; var searchCategoryHelp = '{$searchCategoryHelp|escape:javascript}'; var sitesearchDesc = '{'SitesManager_TrackingSiteSearch'|translate|escape:javascript}'; +var keepURLFragmentSelectHTML = '{$keepURLFragmentSelectHTML|escape:javascript}'; var sitesManager = new SitesManager ( {$timezones}, {$currencies}, '{$defaultTimezone}', '{$defaultCurrency}'); {assign var=searchKeywordLabel value='SitesManager_SearchKeywordLabel'|translate} @@ -147,6 +156,7 @@ vertical-align:middle; <th>{'SitesManager_ExcludedIps'|translate}</th> <th>{'SitesManager_ExcludedParameters'|translate|replace:" ":"<br />"}</th> <th id='exclude-user-agent-header' {if !$allowSiteSpecificUserAgentExclude}style="display:none"{/if}>{'SitesManager_ExcludedUserAgents'|translate}</th> + <th>{'SitesManager_KeepURLFragments'|translate}</th> <th>{'Actions_SubmenuSitesearch'|translate}</th> <th>{'SitesManager_Timezone'|translate}</th> <th>{'SitesManager_Currency'|translate}</th> @@ -165,6 +175,7 @@ vertical-align:middle; <td id="excludedIps" class="editableSite">{foreach from=$site.excluded_ips item=ip}{$ip}<br />{/foreach}</td> <td id="excludedQueryParameters" class="editableSite">{foreach from=$site.excluded_parameters item=parameter}{$parameter}<br />{/foreach}</td> <td id="excludedUserAgents" class="editableSite" {if !$allowSiteSpecificUserAgentExclude}style="display:none"{/if}>{foreach from=$site.excluded_user_agents item=ua}{$ua}<br />{/foreach}</td> + <td id="keepURLFragments" class="editableSite">{if $site.keep_url_fragment eq 0}-{elseif $site.keep_url_fragment eq 1}{'General_Yes'|translate}{else}{'General_No'|translate}{/if}</td> <td id="sitesearch" class="editableSite">{if $site.sitesearch}<span class='sitesearchActive'>{'General_Yes'|translate}</span>{else}<span class='sitesearchInactive'>-</span>{/if}<span class='sskp' sitesearch_keyword_parameters="{$site.sitesearch_keyword_parameters|escape:'html'}" sitesearch_category_parameters="{$site.sitesearch_category_parameters|escape:'html'}" id="sitesearch_parameters"></span></td> <td id="timezone" class="editableSite">{$site.timezone}</td> <td id="currency" class="editableSite">{$site.currency}</td> @@ -234,7 +245,17 @@ vertical-align:middle; <span id='enableSiteUserAgentExclude-loading' class='loadingPiwik' style='display:none'><img src='./themes/default/images/loading-blue.gif' /></span> </td><td>{'SitesManager_EnableSiteSpecificUserAgentExclude_Help'|translate:'<a href="#editSites">':'</a>'|inlineHelp} </td></tr> + + {* global keep URL fragments *} + <tr><td colspan="2"> + <strong>{'SitesManager_KeepURLFragments'|translate}</strong> + <p>{'SitesManager_KeepURLFragmentsHelp'|translate:"<em>#</em>":"<em>http://www.example.org/index.html#first_section</em>":"<em>http://www.example.org/index.html</em>":"<em>http://www.example.org/index.html#second_section</em>"}</p> + <p>{'SitesManager_KeepURLFragmentsHelp2'|translate}</p> + <input type="checkbox" id="globalKeepURLFragments" name="globalKeepURLFragments" {if $globalKeepURLFragments}checked="checked"{/if}/> + <label for="globalKeepURLFragments">{'SitesManager_KeepURLFragmentsLong'|translate}</label> + </td></tr> + {* global site search *} <tr><td colspan="2"> <a name='globalSiteSearch'></a><b>{'SitesManager_TrackingSiteSearch'|translate}</b> <p>{$sitesearchIntro}</p> |