Piwik\Plugins\SitesManager\API::getImageTrackingCode PHP Method

getImageTrackingCode() public method

Returns image link tracking code for a given site with specified options.
public getImageTrackingCode ( integer $idSite, string $piwikUrl = '', $actionName = false, integer $idGoal = false, integer $revenue = false ) : string
$idSite integer The ID to generate tracking code for.
$piwikUrl string The domain and URL path to the Piwik installation.
$idGoal integer An ID for a goal to trigger a conversion for.
$revenue integer The revenue of the goal conversion. Only used if $idGoal is supplied.
return string The HTML tracking code.
    public function getImageTrackingCode($idSite, $piwikUrl = '', $actionName = false, $idGoal = false, $revenue = false)
    {
        $urlParams = array('idsite' => $idSite, 'rec' => 1);
        if ($actionName !== false) {
            $urlParams['action_name'] = urlencode(Common::unsanitizeInputValue($actionName));
        }
        if ($idGoal !== false) {
            $urlParams['idgoal'] = $idGoal;
            if ($revenue !== false) {
                $urlParams['revenue'] = $revenue;
            }
        }
        /**
         * Triggered when generating image link tracking code server side. Plugins can use
         * this event to customise the image tracking code that is displayed to the
         * user.
         *
         * @param string &$piwikHost The domain and URL path to the Piwik installation, eg,
         *                           `'examplepiwik.com/path/to/piwik'`.
         * @param array &$urlParams The query parameters used in the <img> element's src
         *                          URL. See Piwik's image tracking docs for more info.
         */
        Piwik::postEvent('SitesManager.getImageTrackingCode', array(&$piwikUrl, &$urlParams));
        $piwikUrl = (ProxyHttp::isHttps() ? "https://" : "http://") . $piwikUrl . '/piwik.php';
        return "<!-- Piwik Image Tracker-->\n<img src=\"{$piwikUrl}?" . Url::getQueryStringFromParameters($urlParams) . "\" style=\"border:0\" alt=\"\" />\n<!-- End Piwik -->";
    }