src/GoogleCampaignPlugin.php
public static function replaceLink($href, $campaign = array(), $additionalCampaigns = array())
    {
        $href = html_entity_decode($href);
        $params = array();
        $parts = explode('?', $href);
        $uri = $parts[0];

        if (isset($parts[1])) {
            parse_str($parts[1], $params);
        }

        if ( ! count(array_intersect_key($campaign, $params)) and ! array_key_exists(GoogleCampaignPlugin::CAMPAIGN_QUERY_PARAM, $params)) {
            $params = array_merge($params, $campaign);
        } elseif (
            array_key_exists(GoogleCampaignPlugin::CAMPAIGN_QUERY_PARAM, $params)
            and $campaign_name = $params[GoogleCampaignPlugin::CAMPAIGN_QUERY_PARAM]
            and isset($additionalCampaigns[$campaign_name])
        ) {
            unset($params[GoogleCampaignPlugin::CAMPAIGN_QUERY_PARAM]);
            $params = array_merge($params, $additionalCampaigns[$campaign_name]);
        }

        if (count($params)) {
            $uri .= '?'.urldecode(http_build_query($params));
        }

        return $uri;
    }
public static function replaceLink($href, $campaign = array(), $additionalCampaigns = array())
    {
        $href = html_entity_decode($href);
        $params = array();
        $parts = explode('?', $href);
        $uri = $parts[0];

        if (isset($parts[1])) {
            parse_str($parts[1], $params);
        }

        if ( ! count(array_intersect_key($campaign, $params)) and ! array_key_exists(GoogleCampaignPlugin::CAMPAIGN_QUERY_PARAM, $params)) {
            $params = array_merge($params, $campaign);
        } elseif (
            array_key_exists(GoogleCampaignPlugin::CAMPAIGN_QUERY_PARAM, $params)
            and $campaign_name = $params[GoogleCampaignPlugin::CAMPAIGN_QUERY_PARAM]
            and isset($additionalCampaigns[$campaign_name])
        ) {
            unset($params[GoogleCampaignPlugin::CAMPAIGN_QUERY_PARAM]);
            $params = array_merge($params, $additionalCampaigns[$campaign_name]);
        }

        if (count($params)) {
            $uri .= '?'.urldecode(http_build_query($params));
        }

        return $uri;
    }
public static function replaceLink ( $ href , $ campaign = array ( ) , $ additionalCampaigns = array ( ) ) { $ href = html_entity_decode ( $ href ) ; $ params = array ( ) ; $ parts = explode ( '?' , $ href ) ; $ uri = $ parts [ 0 ] ; if ( isset ( $ parts [ 1 ] ) ) { parse_str ( $ parts [ 1 ] , $ params ) ; } if ( ! count ( array_intersect_key ( $ campaign , $ params ) ) and ! array_key_exists ( GoogleCampaignPlugin :: CAMPAIGN_QUERY_PARAM , $ params ) ) { $ params = array_merge ( $ params , $ campaign ) ; } elseif ( array_key_exists ( GoogleCampaignPlugin :: CAMPAIGN_QUERY_PARAM , $ params ) and $ campaign_name = $ params [ GoogleCampaignPlugin :: CAMPAIGN_QUERY_PARAM ] and isset ( $ additionalCampaigns [ $ campaign_name ] ) ) { unset ( $ params [ GoogleCampaignPlugin :: CAMPAIGN_QUERY_PARAM ] ) ; $ params = array_merge ( $ params , $ additionalCampaigns [ $ campaign_name ] ) ; } if ( count ( $ params ) ) { $ uri .= '?' . urldecode ( http_build_query ( $ params ) ) ; } return $ uri ; }
Append campaign parameters to the href attribute of $element object
or replace `google_campaign` parameter with the correct campaign params

@param  string  $href                  the href which needs to be replaced
@param  array   $campaign              the general campaign parameters
@param  array   $additionalCampaigns  additional campaigns for the newsletter
@return DomNode the $element with replaced href attribute
Append campaign parameters to the href attribute of $element object or replace google_campaign parameter with the correct campaign params