• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to install Google Analytics’ Enhanced Ecommerce Features in Codeigniter

#1
I am trying to implement Google Analytics. First step I did is addes this code in header file

Code:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-*********-*"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-*********-*');
</script>

This is working fine and its tracking users.

Now I want to implement Enhanced Ecommerce. For now I am only interested in Purchase event.

Documentation says I should add this code

Code:
ga('create', 'UA-XXXXX-Y');
ga('require', 'ec');

ga('ec:addProduct', {
  'id': 'P12345',
  'name': 'Android Warhol T-Shirt',
  'category': 'Apparel',
  'brand': 'Google',
  'variant': 'black',
  'price': '29.20',
  'quantity': 1
});

// Transaction level information is provided via an actionFieldObject.
ga('ec:setAction', 'purchase', {
  'id': 'T12345',
  'affiliation': 'Google Store - Online',
  'revenue': '37.39',
  'tax': '2.85',
  'shipping': '5.34',
  'coupon': 'SUMMER2013'    // User added a coupon at checkout.
});

ga('send', 'pageview');     // Send transaction data with initial pageview.
My question is that should I add this code in header file where I added initial code ?

My second question is that if I just copy and paste this code in header file and only change I make is UA-XXXXX-Y. And make a puchase on website, will it show something on analytics? I know I have to change code to be dynamic but just for testing I want basic code which I should just copy and paste.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.