Let the platform do the work

Tracking Campaign Activities When Sugar Is Behind a Firewall

Overview

If you host Sugar on a server outside the SugarCloud service, you may elect to put that server behind a firewall as a security measure. In the event that you still want to send campaigns from Sugar, you will need to change some configurations to allow for tracking of the campaign activities such as when a target views a message, clicks a link in the email, etc.

Beginning with version 9.1.0, each user's license type (e.g. Sugar Serve) determines what functionality is available as described in the License Types Matrix documentation. Please note that the Campaigns module is not available for Sugar Serve users.

Resolution

This solution requires the public server to have some method of accessing the server hosting the Sugar instance behind the firewall.

First, save an index.php file on the public server with the following code, where the URL values of http://sugar_url/ are replaced with the actual site URL of your instance.

  <?php 
  if ($_REQUEST['entryPoint'] == 'removeme' || $_REQUEST['entryPoint'] == 'campaign_trackerv2' || $_REQUEST['entryPoint'] == 'image') { 
    if (strlen($_REQUEST['identifier']) == 36) { 
      $ch = curl_init(); if (strlen($_REQUEST['track']) > 0) {
        curl_setopt($ch, CURLOPT_URL, "http://sugar_url/index.php?entryPoint=" . $_REQUEST['entryPoint'] . "&identifier=" . $_REQUEST['identifier'] . "&track=" . $_REQUEST['track']);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
        $headers = curl_exec($ch); 
        $headerArray = explode("\n",$headers);
        foreach ($headerArray as $value) { 
          if (substr(strtolower($value),0,8) == "location") { 
            header($value); 
          }
        }
      } 
      else { 
        curl_setopt($ch, CURLOPT_URL, "http://sugar_url/index.php?entryPoint=" . $_REQUEST['entryPoint'] . "&identifier=" . $_REQUEST['identifier']);
        curl_setopt($ch, CURLOPT_HEADER, 0); 
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_exec($ch);
      } 
      curl_close($ch); unset($ch); 
    }
  }
?>

Finally, navigate to Admin > Campaign Email Settings and enter the external server URL for the "Location of campaign tracking files" option in order for the tracking links to be correctly generated in the campaign emails.