library/core/class.statistics.php
public function AddView($ViewType = 'normal') {
      // Add a pageview entry.
      $TimeSlot = date('Ymd');
      $Px = Gdn::Database()->DatabasePrefix;
      
      $Views = 1;
      $EmbedViews = 0;
      
      try {
         if (C('Garden.Analytics.Views.Denormalize', FALSE) && Gdn::Cache()->ActiveEnabled()) {
            $CacheKey = "QueryCache.Analytics.CountViews";
            
            // Increment. If not success, create key.
            $Incremented = Gdn::Cache()->Increment($CacheKey);
            if ($Incremented === Gdn_Cache::CACHEOP_FAILURE)
               Gdn::Cache()->Store($CacheKey, 1);
            
            // Get current cache value
            $Views = Gdn::Cache()->Get($CacheKey);
            
            if ($ViewType == 'embed') {
               $EmbedCacheKey = "QueryCache.Analytics.CountEmbedViews";

               // Increment. If not success, create key.
               $EmbedIncremented = Gdn::Cache()->Increment($EmbedCacheKey);
               if ($EmbedIncremented === Gdn_Cache::CACHEOP_FAILURE)
                  Gdn::Cache()->Store($EmbedCacheKey, 1);

               // Get current cache value
               $EmbedViews = Gdn::Cache()->Get($EmbedCacheKey);
            }
            
            // Every X views, writeback to AnalyticsLocal
            $DenormalizeWriteback = C('Garden.Analytics.Views.DenormalizeWriteback', 10);
            if (($Views % $DenormalizeWriteback) == 0) {
               Gdn::Controller()->SetData('WritebackViews', $Views);
               Gdn::Controller()->SetData('WritebackEmbed', $EmbedViews);
                  
               Gdn::Database()->Query("insert into {$Px}AnalyticsLocal (TimeSlot, Views, EmbedViews) values (:TimeSlot, {$Views}, {$EmbedViews})
               on duplicate key update 
                  Views = COALESCE(Views, 0)+{$Views}, 
                  EmbedViews = COALESCE(EmbedViews, 0)+{$EmbedViews}", 
               array(
                  ':TimeSlot' => $TimeSlot
               ));
               
               // ... and get rid of those views from the keys
               
               if ($Views)
                  Gdn::Cache()->Decrement($CacheKey, $Views);
               
               if ($EmbedViews)
                  Gdn::Cache()->Decrement($EmbedCacheKey, $EmbedViews);
            }
         } else {
            $ExtraViews = 1;
            $ExtraEmbedViews = ($ViewType == 'embed') ? 1 : 0;
            
            Gdn::Database()->Query("insert into {$Px}AnalyticsLocal (TimeSlot, Views, EmbedViews) values (:TimeSlot, {$ExtraViews}, {$ExtraEmbedViews})
               on duplicate key update 
                  Views = COALESCE(Views, 0)+{$ExtraViews}, 
                  EmbedViews = COALESCE(EmbedViews, 0)+{$ExtraEmbedViews}", 
            array(
               ':TimeSlot' => $TimeSlot
            ));
         }
      } catch (Exception $Ex) {
         if (Gdn::Session()->CheckPermission('Garden.Settings.Manage'))
            throw $Ex;
      }
   }
public function AddView($ViewType = 'normal') {
      // Add a pageview entry.
      $TimeSlot = date('Ymd');
      $Px = Gdn::Database()->DatabasePrefix;
      
      $Views = 1;
      $EmbedViews = 0;
      
      try {
         if (C('Garden.Analytics.Views.Denormalize', FALSE) && Gdn::Cache()->ActiveEnabled()) {
            $CacheKey = "QueryCache.Analytics.CountViews";
            
            // Increment. If not success, create key.
            $Incremented = Gdn::Cache()->Increment($CacheKey);
            if ($Incremented === Gdn_Cache::CACHEOP_FAILURE)
               Gdn::Cache()->Store($CacheKey, 1);
            
            // Get current cache value
            $Views = Gdn::Cache()->Get($CacheKey);
            
            if ($ViewType == 'embed') {
               $EmbedCacheKey = "QueryCache.Analytics.CountEmbedViews";

               // Increment. If not success, create key.
               $EmbedIncremented = Gdn::Cache()->Increment($EmbedCacheKey);
               if ($EmbedIncremented === Gdn_Cache::CACHEOP_FAILURE)
                  Gdn::Cache()->Store($EmbedCacheKey, 1);

               // Get current cache value
               $EmbedViews = Gdn::Cache()->Get($EmbedCacheKey);
            }
            
            // Every X views, writeback to AnalyticsLocal
            $DenormalizeWriteback = C('Garden.Analytics.Views.DenormalizeWriteback', 10);
            if (($Views % $DenormalizeWriteback) == 0) {
               Gdn::Controller()->SetData('WritebackViews', $Views);
               Gdn::Controller()->SetData('WritebackEmbed', $EmbedViews);
                  
               Gdn::Database()->Query("insert into {$Px}AnalyticsLocal (TimeSlot, Views, EmbedViews) values (:TimeSlot, {$Views}, {$EmbedViews})
               on duplicate key update 
                  Views = COALESCE(Views, 0)+{$Views}, 
                  EmbedViews = COALESCE(EmbedViews, 0)+{$EmbedViews}", 
               array(
                  ':TimeSlot' => $TimeSlot
               ));
               
               // ... and get rid of those views from the keys
               
               if ($Views)
                  Gdn::Cache()->Decrement($CacheKey, $Views);
               
               if ($EmbedViews)
                  Gdn::Cache()->Decrement($EmbedCacheKey, $EmbedViews);
            }
         } else {
            $ExtraViews = 1;
            $ExtraEmbedViews = ($ViewType == 'embed') ? 1 : 0;
            
            Gdn::Database()->Query("insert into {$Px}AnalyticsLocal (TimeSlot, Views, EmbedViews) values (:TimeSlot, {$ExtraViews}, {$ExtraEmbedViews})
               on duplicate key update 
                  Views = COALESCE(Views, 0)+{$ExtraViews}, 
                  EmbedViews = COALESCE(EmbedViews, 0)+{$ExtraEmbedViews}", 
            array(
               ':TimeSlot' => $TimeSlot
            ));
         }
      } catch (Exception $Ex) {
         if (Gdn::Session()->CheckPermission('Garden.Settings.Manage'))
            throw $Ex;
      }
   }
public function AddView ( $ ViewType = 'normal' ) { // Add a pageview entry. $ TimeSlot = date ( 'Ymd' ) ; $ Px = Gdn :: Database ( ) -> DatabasePrefix ; $ Views = 1 ; $ EmbedViews = 0 ; try { if ( C ( 'Garden.Analytics.Views.Denormalize' , FALSE ) && Gdn :: Cache ( ) -> ActiveEnabled ( ) ) { $ CacheKey = "QueryCache.Analytics.CountViews" ; // Increment. If not success, create key. $ Incremented = Gdn :: Cache ( ) -> Increment ( $ CacheKey ) ; if ( $ Incremented === Gdn_Cache :: CACHEOP_FAILURE ) Gdn :: Cache ( ) -> Store ( $ CacheKey , 1 ) ; // Get current cache value $ Views = Gdn :: Cache ( ) -> Get ( $ CacheKey ) ; if ( $ ViewType == 'embed' ) { $ EmbedCacheKey = "QueryCache.Analytics.CountEmbedViews" ; // Increment. If not success, create key. $ EmbedIncremented = Gdn :: Cache ( ) -> Increment ( $ EmbedCacheKey ) ; if ( $ EmbedIncremented === Gdn_Cache :: CACHEOP_FAILURE ) Gdn :: Cache ( ) -> Store ( $ EmbedCacheKey , 1 ) ; // Get current cache value $ EmbedViews = Gdn :: Cache ( ) -> Get ( $ EmbedCacheKey ) ; } // Every X views, writeback to AnalyticsLocal $ DenormalizeWriteback = C ( 'Garden.Analytics.Views.DenormalizeWriteback' , 10 ) ; if ( ( $ Views % $ DenormalizeWriteback ) == 0 ) { Gdn :: Controller ( ) -> SetData ( 'WritebackViews' , $ Views ) ; Gdn :: Controller ( ) -> SetData ( 'WritebackEmbed' , $ EmbedViews ) ; Gdn :: Database ( ) -> Query ( "insert into {$Px}AnalyticsLocal (TimeSlot, Views, EmbedViews) values (:TimeSlot, {$Views}, {$EmbedViews})
               on duplicate key update 
                  Views = COALESCE(Views, 0)+{$Views}, 
                  EmbedViews = COALESCE(EmbedViews, 0)+{$EmbedViews}" , array ( ':TimeSlot' => $ TimeSlot ) ) ; // ... and get rid of those views from the keys if ( $ Views ) Gdn :: Cache ( ) -> Decrement ( $ CacheKey , $ Views ) ; if ( $ EmbedViews ) Gdn :: Cache ( ) -> Decrement ( $ EmbedCacheKey , $ EmbedViews ) ; } } else { $ ExtraViews = 1 ; $ ExtraEmbedViews = ( $ ViewType == 'embed' ) ? 1 : 0 ; Gdn :: Database ( ) -> Query ( "insert into {$Px}AnalyticsLocal (TimeSlot, Views, EmbedViews) values (:TimeSlot, {$ExtraViews}, {$ExtraEmbedViews})
               on duplicate key update 
                  Views = COALESCE(Views, 0)+{$ExtraViews}, 
                  EmbedViews = COALESCE(EmbedViews, 0)+{$ExtraEmbedViews}" , array ( ':TimeSlot' => $ TimeSlot ) ) ; } } catch ( Exception $ Ex ) { if ( Gdn :: Session ( ) -> CheckPermission ( 'Garden.Settings.Manage' ) ) throw $ Ex ; } }
Increments overall pageview view count

@since 2.1a
@access public
Increments overall pageview view count