juliencoquet

Enhanced commerce

Nov 18th, 2014
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. <script>
  2.  
  3. // TVA: ramener TTC sur HT 8%
  4. function arrHT(prixTTC){
  5. var chTVA = 1.08;
  6. var prixHT = prixTTC / chTVA;
  7. return prixHT.toFixed();
  8. }
  9.  
  10. // Variables
  11.  
  12. var _pArray = {{Commande - Produits}};
  13. var tAmount = {{Commande - Montant}};
  14. var tTax = {{Commande - Total TVA}};
  15. var tShipping = {{Commande - Total livraison}};
  16. // Tag
  17. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  18. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  19. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  20. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  21.  
  22. ga('create', {{ID - Google Analytics}});
  23. ga('require', 'ec');
  24.  
  25. for (var j=0;j<_pArray.length;j++){
  26. ga('ec:addProduct', { // Provide product details in an productFieldObject.
  27. 'id': _pArray[j].sku, // Product ID (string).
  28. 'name': _pArray[j].name, // Product name (string).
  29. 'category': _pArray[j].category, // Product category (string).
  30. 'brand': '', // Product brand (string).
  31. 'variant': '', // Product variant (string).
  32. 'price': arrHT(_pArray[j].price), // Product price (currency).
  33. 'coupon': '', // Product coupon (string).
  34. 'quantity': _pArray[j].quantity, // Product quantity (number).
  35. 'dimension11': _pArray[j].livraison,
  36. 'metric2':1
  37. });
  38. }
  39. ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
  40. 'id': '{{Commande - ID}}', // (Required) Transaction id (string).
  41. 'affiliation': '{{Commande - Nom du magasin}}', // Affiliation (string).
  42. 'revenue': arrHT(tAmount), // Revenue (currency).
  43. 'tax': arrHT(tTax), // Tax (currency).
  44. 'shipping': arrHT(tShipping), // Shipping (currency).
  45. 'coupon': '', // Transaction coupon (string).
  46. 'dimension11': _pArray[0].livraison,
  47. 'metric12':1
  48.  
  49. });
  50.  
  51. ga('send', 'event',{
  52. 'eventCategory': 'eCom',
  53. 'eventAction': 'Achat',
  54. 'eventLabel': 'Confirmation'
  55. });
  56. </script>
Advertisement
Add Comment
Please, Sign In to add comment