Index: core/Tracker/Visit.php
===================================================================
--- core/Tracker/Visit.php	(revision 5287)
+++ core/Tracker/Visit.php	(working copy)
@@ -45,6 +45,8 @@
 	protected $visitorKnown;
 	protected $request;
 
+	// Abandonment Tracking
+	protected $trackAbandons;
 	// can be overwritten in constructor
 	protected $timestamp;
 	protected $ip;
@@ -210,7 +212,7 @@
 			$idRefererActionName = $this->visitorInfo['visit_exit_idaction_name'];
 			try {
 				$this->handleKnownVisit($idActionUrl, $idActionName, $visitIsConverted);
-				if(!is_null($action))
+				if(!is_null($action) && !$this->trackAbandons)
 				{
 					$action->record( 	$this->visitorInfo['idvisit'],
 										$this->visitorInfo['idvisitor'],
@@ -373,6 +375,12 @@
 		
 		// Custom Variables overwrite previous values on each page view
 		$valuesToUpdate = array_merge($valuesToUpdate, $this->visitorCustomVariables);
+	
+		// Update visitor's Config settings when tracking Abandons (PHP Can't detect Screen Res, Plugins, etc)
+		if ($this->trackAbandons)
+		{
+			$valuesToUpdate = array_merge($valuesToUpdate, $this->visitorCustomVariables);
+		}
 
 		// trigger event before update
 		Piwik_PostEvent('Tracker.knownVisitorUpdate', $valuesToUpdate);
@@ -407,6 +415,15 @@
 
 		$result = Piwik_Tracker::getDatabase()->query($sqlQuery, $sqlBind);
 
+		//Update 'Abandon' action for current idvisit - Only happens on Visit's first Action ( avoids duplicating action when tracking Abandons)
+		if ($this->trackAbandons)
+		{
+			$updateActionQuery = "UPDATE ". Piwik_Common::prefixTable('log_link_visit_action') ."
+				SET idaction_name = ?, idaction_url = ?
+				WHERE idvisit = ?";
+			$updatedAction = Piwik_Tracker::getDatabase()->query($updateActionQuery, array( $idActionName, $idActionUrl, $this->visitorInfo['idvisit'] ) );
+		}
+
 		$this->visitorInfo['visit_last_action_time'] = $this->getCurrentTimestamp();
 
 		// Debug output
@@ -908,6 +925,9 @@
 			printDebug("Visitor doesn't have the piwik cookie.");
 		}
 
+                $this->trackAbandons = Piwik_Common::getRequestVar('_abdn', 0, 'int', $this->request);
+                printDebug("Was the Abandon Cookie found: ". ($this->trackAbandons > 0 ? 'True' : 'False') );
+
 		$userInfo = $this->getUserSettingsInformation();
 		$configId = $userInfo['config_id'];
 		$timeLookBack = date('Y-m-d H:i:s', $this->getCurrentTimestamp() - self::TIME_IN_PAST_TO_SEARCH_FOR_VISITOR);
Index: libs/PiwikTracker/PiwikTracker.php
===================================================================
--- libs/PiwikTracker/PiwikTracker.php	(revision 5287)
+++ libs/PiwikTracker/PiwikTracker.php	(working copy)
@@ -78,6 +78,7 @@
     	$this->ecommerceLastOrderTimestamp = false;
     	$this->ecommerceItems = array();
 
+	$this->trackAbandons = false;
     	$this->requestCookie = '';
     	$this->idSite = $idSite;
     	$this->urlReferrer = @$_SERVER['HTTP_REFERER'];
@@ -249,6 +250,18 @@
      */
     public function doTrackPageView( $documentTitle )
     {
+	if ($this->trackAbandons)
+	{
+		$ts = time();
+		if (!$this->getCookieMatchingName('id.'.$this->idSite.'.') )
+		{
+			$this->setFirstPartyCookie('id', $this->visitorId . '.' . $ts . '.1.' . $ts . '.' . $ts );
+		}
+		if (!$this->getCookieMatchingName('abdn.'.$this->idSite.'.') )
+		{
+			$this->setFirstPartyCookie('abdn', $this->visitorId . '.' . $ts);
+		}
+	}
     	$url = $this->getUrlTrackPageView($documentTitle);
     	return $this->sendRequest($url);
     } 
@@ -594,6 +607,27 @@
     	return $this->visitorId;
     }
 
+	/**
+	 * Enable Abandonment Tracking - this will cause a first party VisitorId cookie and Abandon cookie to be set
+	 */
+	public function setTrackAbandons( $track = false )
+	{
+		$this->trackAbandons = $track;
+	}
+
+	/**
+	 * Sets a first party cookie.  This is useful when using the PHP Tracking API along with the Javascript Tracking API.
+	 *
+	 * @return bool
+	 */
+	protected function setFirstPartyCookie($baseName, $value)
+	{
+		$hash = substr( sha1( self::getCurrentHost() . '/' ), 0, 4);
+		$name = '_pk_' . $baseName . '.' . $this->idSite . '.' . $hash;
+
+		return setcookie( $name, $value, null, '/', '' );
+	}
+
     /**
      * Returns the currently assigned Attribution Information stored in a first party cookie.
      * 
Index: js/piwik.js
===================================================================
--- js/piwik.js	(revision 5287)
+++ js/piwik.js	(working copy)
@@ -1251,6 +1251,17 @@
 
 				lastActivityTime = now.getTime();
 			}
+			
+			/*
+			 * Get Abandon cookie. This cookie is only needed once at the beginning of the visit, remove once found.
+			 */
+			function getAbandonCookie() {
+				var trackAbandons = getCookie( getCookieName('abdn') ) !== 0 ? true : false;
+				if (trackAbandons) {
+					setCookie( getCookieName('abdn'), '', -1, configCookiePath, configCookieDomain);
+				}
+				return trackAbandons;
+			}
 
 			/*
 			 * Sets the Visitor ID cookie: either the first time loadVisitorIdCookie is called
@@ -1465,6 +1476,7 @@
 				// build out the rest of the request
 				request += '&idsite=' + configTrackerSiteId +
 					'&rec=1' +
+					(getAbandonCookie() ? '&_abdn=1' : '') +
 					'&r=' + String(Math.random()).slice(2, 8) + // keep the string to a minimum
 					'&h=' + now.getHours() + '&m=' + now.getMinutes() + '&s=' + now.getSeconds() +
 					'&url=' + encodeWrapper(purify(currentUrl)) +
