Index: trunk/extensions/DonationInterface/payflowpro_gateway/api_payflowpro_gateway.php |
— | — | @@ -114,8 +114,16 @@ |
115 | 115 | // fetch the CSRF prevention token and set it if it's not already set |
116 | 116 | $token = PayflowProGateway::fnPayflowEditToken( $wgPayflowGatewaySalt ); |
117 | 117 | |
| 118 | + // retrieve and unpack the json encoded string of tracking data |
| 119 | + $tracking_data = json_decode( $params[ 'tracking_data' ], true ); |
| 120 | + |
| 121 | + // ensure the utm_source is formatted correctly |
| 122 | + $utm_source_str = ( isset( $tracking_data[ 'utm_source' ] )) ? $tracking_data[ 'utm_source' ] : null; |
| 123 | + $utm_source_id = ( isset( $tracking_data[ 'utm_source_id' ] )) ? $tracking_data[ 'utm_source_id' ] : null; |
| 124 | + $tracking_data[ 'utm_source' ] = PayflowProGateway::getUtmSource( $utm_source_str, $utm_source_id ); |
| 125 | + |
118 | 126 | // fetch the contribution_tracking_id by inserting tracking data to contrib tracking table |
119 | | - $contribution_tracking_id = PayflowProGateway::insertContributionTracking( json_decode( $params[ 'tracking_data' ], true )); |
| 127 | + $contribution_tracking_id = PayflowProGateway::insertContributionTracking( $tracking_data ); |
120 | 128 | |
121 | 129 | // this try/catch design pattern stolen from ClickTracking/ApiSpecialClickTracking.php |
122 | 130 | try { |
Index: trunk/extensions/DonationInterface/payflowpro_gateway/payflowpro_gateway.body.php |
— | — | @@ -933,7 +933,7 @@ |
934 | 934 | 'order_id' => $order_id, |
935 | 935 | 'numAttempt' => $numAttempt, |
936 | 936 | 'referrer' => 'http://www.baz.test.com/index.php?action=foo&action=bar', |
937 | | - 'utm_source' => $this->getUtmSource(), |
| 937 | + 'utm_source' => self::getUtmSource(), |
938 | 938 | 'utm_medium' => $wgRequest->getText( 'utm_medium' ), |
939 | 939 | 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ), |
940 | 940 | 'language' => 'en', |
— | — | @@ -968,7 +968,7 @@ |
969 | 969 | 'order_id' => $order_id, |
970 | 970 | 'numAttempt' => $numAttempt, |
971 | 971 | 'referrer' => ( $wgRequest->getVal( 'referrer' )) ? $wgRequest->getVal( 'referrer' ) : $wgRequest->getHeader( 'referer' ), |
972 | | - 'utm_source' => $this->getUtmSource(), |
| 972 | + 'utm_source' => self::getUtmSource(), |
973 | 973 | 'utm_medium' => $wgRequest->getText( 'utm_medium' ), |
974 | 974 | 'utm_campaign' => $wgRequest->getText( 'utm_campaign' ), |
975 | 975 | // try to honr the user-set language (uselang), otherwise the language set in the URL (language) |
— | — | @@ -1015,20 +1015,34 @@ |
1016 | 1016 | * |
1017 | 1017 | * the utm_source is structured as: banner.landing_page.payment_instrument |
1018 | 1018 | * |
| 1019 | + * @param string $utm_source The utm_source for tracking - if not passed directly, |
| 1020 | + * we try to figure it out from the request object |
| 1021 | + * @param int $utm_source_id The utm_source_id for tracking - if not passed directly, |
| 1022 | + * we try to figure it out from the request object |
1019 | 1023 | * @return string The full utm_source |
1020 | 1024 | */ |
1021 | | - public function getUtmSource() { |
| 1025 | + public static function getUtmSource( $utm_source=null, $utm_source_id=null ) { |
1022 | 1026 | global $wgRequest; |
1023 | 1027 | |
1024 | | - // fetch whatever was passed in as the utm_source |
1025 | | - $utm_source = $wgRequest->getText( 'utm_source' ); |
| 1028 | + /** |
| 1029 | + * fetch whatever was passed in as the utm_source |
| 1030 | + * |
| 1031 | + * if utm_source was not passed in as a param, we try to divine it from |
| 1032 | + * the request. if it's not set there, no big deal, we'll just be |
| 1033 | + * missing some tracking data. |
| 1034 | + */ |
| 1035 | + if ( is_null( $utm_source )) { |
| 1036 | + $utm_source = $wgRequest->getText( 'utm_source' ); |
| 1037 | + } |
1026 | 1038 | |
1027 | 1039 | /** |
1028 | 1040 | * if we have a utm_source_id, then the user is on a single-step credit card form. |
1029 | 1041 | * if that's the case, we treat the single-step credit card form as a landing page, |
1030 | 1042 | * which we label as cc#, where # = the utm_source_id |
1031 | 1043 | */ |
1032 | | - $utm_source_id = $wgRequest->getVal( 'utm_source_id', 0 ); |
| 1044 | + if ( is_null( $utm_source_id )) { |
| 1045 | + $utm_source_id = $wgRequest->getVal( 'utm_source_id', 0 ); |
| 1046 | + } |
1033 | 1047 | |
1034 | 1048 | // this is how the CC portion of the utm_source should be defined |
1035 | 1049 | $correct_cc_source = ( $utm_source_id ) ? 'cc' . $utm_source_id . '.cc' : 'cc'; |