Commerce checkout: Google AdWords conversion pane

Public

Creates a checkout pane in Drupal Commerce for Google AdWords tracking

</> CopyGet raw version
php
  1. <?php
  2. /**
  3.  * @file checkout_pane_shipping_details.module
  4.  * Adds a new pane that creates a text message for describing shipping methods
  5.  */
  6.  
  7. /**
  8.  * Implements hook_commerce_checkout_pane_info().
  9.  *
  10.  * This is where we define the name of the pane, related information, and
  11.  * the base name of all the form builder functions used to present the
  12.  * pane.
  13.  */
  14. function mymodule_commerce_checkout_pane_info() {
  15.  
  16. $panes['checkout_pane_adwords'] = array(
  17. 'title' => '',
  18. 'base' => 'checkout_pane_adwords_pane',
  19.  
  20. // The checkout page where this should be displayed by default.
  21. 'page' => 'complete',
  22. 'weight' => 60,
  23. );
  24.  
  25. return $panes;
  26. }
  27. /**
  28.  * Example Pane: form callback.
  29.  *
  30.  * This is a standard FAPI form which will be presented in the pane.
  31.  * The form gathers and stores information from $order->data, an array which
  32.  * can be populated with free-form keys and values.
  33.  */
  34. function checkout_pane_adwords_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
  35. $message = '
  36. <!-- Google Code for Internet Sale Conversion Page -->
  37. <script type="text/javascript">
  38. /* <![CDATA[ */
  39. var google_conversion_id = YOUR_ADWORDS_ID;
  40. var google_conversion_language = "en";
  41. var google_conversion_format = "2";
  42. var google_conversion_color = "ffffff";
  43. var google_conversion_label = "YOUR_LABEL";
  44. var google_conversion_value = 0;
  45. /* ]]> */
  46. </script>
  47. <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
  48. </script>
  49. <noscript>
  50. <div style="display:inline;">
  51. <img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/1041075554/?value=0&amp;label=rObDCJqUmQUQ4pq28AM&amp;guid=ON&amp;script=0"/>
  52. </div>
  53. </noscript>
  54. ';
  55. $pane_form['checkout_pane_adwords'] = array(
  56. '#markup' => $message
  57. );
  58. return $pane_form;
  59. }