r75048 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75047‎ | r75048 | r75049 >
Date:22:00, 19 October 2010
Author:awjrichards
Status:deferred
Tags:
Comment:
Updated naming convention for owa module -> wmf_owa
Modified paths:
  • /civicrm/trunk/sites/all/modules/wmf_owa (added) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/wmf_owa/owa.info
@@ -0,0 +1,3 @@
 2+name = Open Web Analytics for Wikimedia Foundation
 3+description = Allows for tracking of WMF-specific events in Open Web Analytics
 4+core = 6.x
\ No newline at end of file
Index: civicrm/trunk/sites/all/modules/wmf_owa/owa.module
@@ -0,0 +1,87 @@
 2+<?php
 3+
 4+/**
 5+ * Callback for menu path "admin/settings/wmf_owa".
 6+ */
 7+function wmf_owa_settings() {
 8+ $form[ 'wmf_owa_log' ] = array(
 9+ '#type' => 'textfield',
 10+ '#title' => t( 'OWA log path' ),
 11+ '#required' => TRUE,
 12+ '#default_value' => variable_get('wmf_owa_log', 'http://analytics.tesla.usability.wikimedia.org/wiki/d/extensions/owa/log.php'),
 13+ );
 14+}
 15+
 16+/**
 17+ * Format and send contribution tracking data to OWA
 18+ * @param array $msg Array containing contribution information
 19+ */
 20+function wmf_owa_record_contribution( $msg ){
 21+//NEED:
 22+//utm_campaign
 23+//referer URL
 24+//owa_session_id
 25+//OWA log URL
 26+
 27+ // format the contribution tracking message
 28+ $query_params = array(
 29+ "owa_event_type" => "ecommerce.transaction",
 30+ "owa_ct_order_id" => $msg[ 'contribution_tracking_id' ],
 31+ "owa_ct_order_source" => $data['utm_campaign'],
 32+ "owa_ct_total" => $msg['gross'],
 33+ "owa_ct_tax" => 0,
 34+ "owa_ct_shipping" => 0,
 35+ "owa_ct_gateway" => $msg['gateway'],
 36+ "owa_page_url" => $encodedReqURL,
 37+ //ct_line_items[li_product_name]=foo&
 38+ "owa_session_id"=> "some_id"
 39+ );
 40+
 41+ // send the tracking message to OWA
 42+ wmf_owa_send_tracking( $query_params );
 43+}
 44+
 45+/**
 46+ * Implementation of hook_civicrm_post
 47+ *
 48+ * @param unknown_type $op
 49+ * @param unknown_type $objectName
 50+ * @param unknown_type $objectId
 51+ * @param unknown_type $objectRef
 52+ */
 53+function wmf_owa_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
 54+ // only continue if we're handling a new or updated contribution
 55+ if ( $objectName != 'Contribution' && !in_array( $op, array( 'edit', 'create' )) ) {
 56+ return;
 57+ }
 58+ var_dump( $objectRef ); exit;
 59+ // load the OWA
 60+ //$contribution_tracking_data = wmf_owa_get_contribution_tracking_data( $objectId );
 61+
 62+}
 63+
 64+
 65+/**
 66+ * Fetch info needed for OWA from contribution_tracking table
 67+ * @param int $contribution_tracking_id
 68+ */
 69+function wmf_owa_get_contribution_tracking_data( $contribution_id ) {
 70+ $query = 'SELECT ct.id as "contribuion_tracking_id", ct.owa_session, ctor.url, ct.utm_campaign
 71+ FROM contribution_tracking ct, contribution_tracking_owa_ref ctor
 72+ WHERE ctor.id=ct.owa_ref && ct.contribution_id="%d"';
 73+ return db_fetch_object( db_query( $query, $contribution_id ));
 74+}
 75+
 76+/**
 77+ * Send tracking data to OWA
 78+ *
 79+ * @param array $query_params The array of data for OWA to track
 80+ */
 81+function wmf_owa_send_tracking( $query_params ) {
 82+ $owa_log_url = variable_get( 'wmf_owa_log', 'http://analytics.tesla.usability.wikimedia.org/wiki/d/extensions/owa/log.php' );
 83+ $ch = curl_init();
 84+ curl_setopt( $ch, CURLOPT_URL, $owa_log_url . "?". http_build_query( $query_params ));
 85+ curl_setopt( $ch, CURLOPT_USERAGENT, "WMF Ecommerce web service 1.0" );
 86+ curl_exec( $ch );
 87+ curl_close( $ch );
 88+}
\ No newline at end of file

Status & tagging log