Advertisement
chrishajer

Get authorize.net transaction code into GA tracking

Feb 20th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2. // originally from Alex in Help Scout 20 February 2013
  3. add_filter("gform_confirmation", "custom_confirmation", 10, 4);
  4. function custom_confirmation($confirmation, $form, $lead, $ajax){
  5.     if($form["id"] == "102"){
  6.         $transaction_id = GFAuthorizeNet::$transaction_response["transaction_id"];
  7.         $confirmation .= "<script type='text/javascript'>
  8.  
  9. var _gaq = _gaq || [];
  10. _gaq.push(['_setAccount', 'UA-2360178-80']);
  11. _gaq.push(['_trackPageview']);
  12. _gaq.push(['_addTrans','{$transaction_id}', // transaction ID - required
  13. 'American Knight Promotion', // affiliation or store name
  14. '{Total:24}', // total - required
  15. '0', // tax
  16. '0', // shipping
  17. '{Address (City):28.3}', // city
  18. '{Address (State / Province):28.4}', // state or province
  19. 'USA' // country
  20. ]);
  21.  
  22. // add item might be called for every item in the shopping cart
  23. // where your ecommerce engine loops through each item in the cart and
  24. // prints out _addItem for each
  25. _gaq.push(['_addItem', '{$transaction_id}', // transaction ID - required
  26. '978-0-9882148-0-4', // SKU/code - required
  27. 'Return to Order - Hardcover', // product name
  28. 'Hard cover', // category or variation
  29. '{Return to Order - Hardcover (Price):26.2}', // unit price - required
  30. '{Return to Order - Hardcover (Quantity):26.3}' // quantity - required
  31. ]);
  32. _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
  33.  
  34. (function() {
  35. var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  36. ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  37. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  38. })();
  39.  
  40. </script>";
  41.     }
  42.  
  43.     return $confirmation;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement