Beispiel #1
0
 /**
  * Update a site's tracking code
  *
  * @param int $siteId
  *        	which Piwik site to updated
  * @param int $blogId
  *        	which blog's Piwik site ID to get, default is the current blog
  * @return string tracking code
  */
 public function updateTrackingCode($siteId = false, $blogId = null)
 {
     if (!$siteId) {
         $siteId = $this->getPiwikSiteId();
     }
     if (self::$settings->getGlobalOption('track_mode') == 'disabled' || self::$settings->getGlobalOption('track_mode') == 'manually') {
         return false;
     }
     $id = WP_Piwik\Request::register('SitesManager.getJavascriptTag', array('idSite' => $siteId, 'mergeSubdomains' => self::$settings->getGlobalOption('track_across') ? 1 : 0, 'mergeAliasUrls' => self::$settings->getGlobalOption('track_across_alias') ? 1 : 0, 'disableCookies' => self::$settings->getGlobalOption('disable_cookies') ? 1 : 0));
     $code = $this->request($id);
     if (is_array($code) && isset($code['value'])) {
         $code = $code['value'];
     }
     $result = !is_array($code) ? html_entity_decode($code) : '<!-- ' . json_encode($code) . ' -->';
     self::$logger->log('Delivered tracking code: ' . $result);
     $result = WP_Piwik\TrackingCode::prepareTrackingCode($result, self::$settings, self::$logger, true);
     if (isset($result['script']) && !empty($result['script'])) {
         self::$settings->setOption('tracking_code', $result['script'], $blogId);
         self::$settings->setOption('noscript_code', $result['noscript'], $blogId);
         self::$settings->setGlobalOption('proxy_url', $result['proxy'], $blogId);
     }
     return $result;
 }
Beispiel #2
0
 function get_visitor_profile()
 {
     // Get Site ID
     $piwik_instance = $GLOBALS['wp-piwik'];
     $id_site = $piwik_instance->getPiwikSiteId();
     $ip_site = $_SERVER['REMOTE_ADDR'];
     $ip_range_min = substr($ip_site, 0, strlen($ip_site) - 1) . 0;
     $ip_range_max = substr($ip_site, 0, strlen($ip_site) - 1) . 255;
     // Get Visitor ID based on IP
     $visit_details_request = WP_Piwik\Request::register('Live.getLastVisitsDetails', array('idSite' => $id_site, 'period' => 'day', 'date' => 'today', 'daysSinceLastVisit' => 0, 'segment' => '&visitIp>' . urlencode($ip_range_min) . ';visitIp<' . urlencode($ip_range_max)));
     $visit_details = $piwik_instance->request($visit_details_request);
     // Get Profile
     $visitor_id = $visit_details[0]['visitorId'];
     $profile_request = WP_Piwik\Request::register('Live.getVisitorProfile', array('idSite' => $id_site, 'visitorId' => $visitor_id, 'flat' => 1));
     return $piwik_instance->request($profile_request);
 }