SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Location
    Battle Ground, Washington, United States
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Google Analytics and Ecommerce code

    I'm having a little trouble with the code I've input for my google analytics to track our sales from our website. I created a code based on google's instructions and it reports whenever someone buys something from the store, unfortunately it reports that those people are buying one of EVERYTHING from the store, as you can see in this screenshot:

    https://www.evernote.com/shard/s113/...9a751eeb73631c

    I don't know what I did to make it do this and how to set it up so it only reports exactly what the customer bought. This is the code I put into my godaddy invoice section, as per google's instructions. Anyone see something I'm doing wrong?

    Code:
    <script type="text/javascript">
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-29095748-1']);
      _gaq.push(['_trackPageview']);
      _gaq.push(['_addTrans',
        '1234',           // order ID - required
        'KoolCollar',  // affiliation or store name
        '16.99',          // total - required
        '1.29',           // tax
        '5',              // shipping
        'Vancouver',       // city
        'Washington',     // state or province
        'USA'             // country
      ]);
    
       // add item might be called for every item in the shopping cart
       // where your ecommerce engine loops through each item in the cart and
       // prints out _addItem for each
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1203',           // SKU/code - required
        'Large Black KoolCollar w/ KoolTube',        // product name
        'Large KoolCollars',   // category or variation
        '17.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1103',           // SKU/code - required
        'Large Blue KoolCollar w/ KoolTube',        // product name
        'Large KoolCollars',   // category or variation
        '17.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1703',           // SKU/code - required
        'Large Red KoolCollar w/ KoolTube',        // product name
        'Large KoolCollars',   // category or variation
        '17.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KT103',           // SKU/code - required
        'Large KoolTube Refills',        // product name
        'Large KoolTube',   // category or variation
        '7.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1202',           // SKU/code - required
        'Medium Black KoolCollar w/ KoolTube',        // product name
        'Medium KoolCollar',   // category or variation
        '16.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1102',           // SKU/code - required
        'Medium Blue KoolCollar w/ KoolTube',        // product name
        'Medium KoolCollar',   // category or variation
        '16.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1702',           // SKU/code - required
        'Medium Red KoolCollar w/ KoolTube',        // product name
        'Medium KoolCollar',   // category or variation
        '16.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KT102',           // SKU/code - required
        'Medium KoolTube Refill',        // product name
        'Medium KoolTube',   // category or variation
        '6.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1201',           // SKU/code - required
        'Small Black KoolCollar w/ KoolTube',        // product name
        'Small KoolCollar',   // category or variation
        '15.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1101',           // SKU/code - required
        'Small Blue KoolCollar w/ KoolTube',        // product name
        'Small KoolCollar',   // category or variation
        '15.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1701',           // SKU/code - required
        'Small Red KoolCollar w/ KoolTube',        // product name
        'Small KoolCollar',   // category or variation
        '15.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KT101',           // SKU/code - required
        'Small KoolTube Refill',        // product name
        'Small KoolTube',   // category or variation
        '5.99',          // unit price - required
        '1'               // quantity - required
      ]);
    
      _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
    
    </script>

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Aug 2003
    Location
    Southern California
    Posts
    4,686
    Mentioned
    19 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ajrdesign View Post
    I don't know what I did to make it do this and how to set it up so it only reports exactly what the customer bought. This is the code I put into my godaddy invoice section, as per google's instructions. Anyone see something I'm doing wrong?
    Your code is listing out every product as a part of the transaction thus Google is showing exactly what you told them to record.

    You should be dynamically building this information starting with the order summary.

    Code:
    '1234',           // order ID - required
        'KoolCollar',  // affiliation or store name
        '16.99',          // total - required
        '1.29',           // tax
        '5',              // shipping
        'Vancouver',       // city
        'Washington',     // state or province
        'USA'             // country
      ]);
    And then looping through the products purchased using the format

    Code:
    _gaq.push(['_addItem',
        '1234',           // order ID - required
        'KC1203',           // SKU/code - required
        'Large Black KoolCollar w/ KoolTube',        // product name
        'Large KoolCollars',   // category or variation
        '17.99',          // unit price - required
        '1'               // quantity - required
      ]);
    How you handle the dynamic insertion will depend on your ecommerce software.
    - Ted S

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Location
    Battle Ground, Washington, United States
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by "dynamically building" the information? With PHP?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Aug 2003
    Location
    Southern California
    Posts
    4,686
    Mentioned
    19 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ajrdesign View Post
    What do you mean by "dynamically building" the information? With PHP?
    You're telling Google what was in the order. Since all orders are not the same this needs to be done dynamically putting the right totals, shipping costs, and products in. Right now your code is static and says to google "all these products are in this order" no matter what is actually in the order.

    You'll need to use whatever language your cart supports that you like best.
    - Ted S

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Location
    Battle Ground, Washington, United States
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok that makes sense. How do I find out what language my cart supports? I'm using Godaddy shopping cart and I'm having trouble finding the right dynamic code to put in to make it access the information.

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Aug 2003
    Location
    Southern California
    Posts
    4,686
    Mentioned
    19 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ajrdesign View Post
    Ok that makes sense. How do I find out what language my cart supports? I'm using Godaddy shopping cart and I'm having trouble finding the right dynamic code to put in to make it access the information.
    I'd start with their support team as this is presumably a very common question. If not them, you can search on their cart and the issue as again, it's something most stores do.
    - Ted S


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •