public function logPageArrival()
 {
     $lastPageViews = PageView::get("PageView", "VisitorID = {$this->ID}");
     if ($lastPageViews->count() > 0) {
         $scrollDepth = 0;
         $vidLength = 0;
         $lastPageView = $lastPageViews->last();
         // Calculate the time on the previous page
         $startTime = strtotime($lastPageView->Created);
         $endTime = time();
         $timeOnPage = $endTime - $startTime;
         // Check if a scroll depth for the previous page was sent through
         if (isset($_COOKIE["vt_sd"])) {
             // Get the scroll depth
             $scrollDepth = (int) $_COOKIE["vt_sd"];
         }
         if (isset($_COOKIE['vid-start']) && isset($_COOKIE['vid-end'])) {
             $vidLength = (int) $_COOKIE['vid-end'] - (int) $_COOKIE['vid-start'];
             setcookie("vid-start", "", time() - 3600);
             setcookie("vid-end", "", time() - 3600);
         }
         $lastPageView->ScrollDepth = $scrollDepth;
         $lastPageView->TimeOnPage = $timeOnPage;
         if ($vidLength > 0) {
             $lastPageView->Notes = "The video on this page was viewed for " . $vidLength . " seconds";
         }
         $lastPageView->write();
     }
     // Save this page view (Scroll depth will be updated on the next page's view)
     $PageView = PageView::create(array('VisitorID' => $this->ID, 'URL' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "", 'Referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "", 'UserAgent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "", 'Cookie' => isset($_SERVER['HTTP_COOKIE']) ? $_SERVER['HTTP_COOKIE'] : "", 'ScrollDepth' => 0, 'Notes' => ''));
     $PageView->write();
 }