Integrating E-Commerce Tracking in Google Analytics

Discussion in 'Google' started by flux627, Jun 4, 2009.

  1. #1
    Hello all,

    I am wondering if anyone can enlighten me with a solution to my problem.

    I currently have a Goal set up so I know when I get sales and where they come from, but I am looking to add code to track transaction ID and sales total. The thank-you page does not include a receipt, however the desired information is embedded in the URL of the thank-you page.

    This is an example taken from a real generated thank-you page:

    .../Member/PaymentResult.aspx?pm=2&DR=jxRr6MUKsIR37RZrRqgZhqH05nsoe5%2bt1Wr%2fy%2b883jM%3d&tx=2C124930B67583205&st=Completed&amt=4.99&cc=USD&cm=ConxO0xAqzZLJ8uOXxn6tw%3d%3d&item_number=943300

    The first bold text shows the total amount ($4.99 in USD) and the second bold text shows the transaction ID (943300).

    I checked Google's help docs for implementing this code, but I do not know Java, and could not figure it out. If anyone could lend a helping hand, it would be greatly appreciated!

    Thanks,
    Flux
     
    flux627, Jun 4, 2009 IP
  2. ColeenB

    ColeenB Peon

    Messages:
    123
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here's the google code for your thank-you page:

    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'
    type='text/javascript' %3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("UA-XXXXX-1");
    pageTracker._trackPageview();

    pageTracker._addTrans(
    "1234", // Order ID
    "Mountain View", // Affiliation
    "11.99", // Total
    "1.29", // Tax
    "5", // Shipping
    "San Jose", // City
    "California", // State
    "USA" // Country
    );

    pageTracker._addItem(
    "1234", // Order ID
    "DD44", // SKU
    "T-Shirt", // Product Name
    "Green Medium", // Category
    "11.99", // Price
    "1" // Quantity
    );
    pageTracker._trackTrans();
    } catch(err) {}</script>

    All of the parameters are necessary, so if you don't need them, keep them in and leave them empty. I THINK it should look like this in your case:

    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'
    type='text/javascript' %3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("UA-XXXXX-1");
    pageTracker._trackPageview();

    pageTracker._addTrans(
    "{item_number}", // Order ID
    "", // Affiliation
    "{Completed&amt}", // Total
    "", // Tax
    "", // Shipping
    "", // City
    "", // State
    "" // Country
    );

    pageTracker._addItem(
    "{item_number}", // Order ID
    "", // SKU
    "", // Product Name
    "", // Category
    "", // Price
    "" // Quantity
    );
    pageTracker._trackTrans();
    } catch(err) {}</script>


    Put your own Analytics code in the appropriate place. And make sure that you change E-Commerce Website to Yes in the Profile Settings in Analytics.

    Good luck!
     
    ColeenB, Jun 4, 2009 IP
  3. flux627

    flux627 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I will try this and report back.

    Thank you!
     
    flux627, Jun 4, 2009 IP
  4. flux627

    flux627 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So, I've run into another problem.

    It seems that I do not have the ability to modify my thank-you page by itself. (I'm being forced to use this stupid system.) I can, however, add code that is present on every page. Is it possible to set up a javascript that will only allow code to run if the URL starts with a given header?

    Or, what would happen if the E-commerce script was on every page? Only the payment pages have these variables in the URL.
     
    flux627, Jun 4, 2009 IP
  5. ColeenB

    ColeenB Peon

    Messages:
    123
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I imagine that the values would only be passed back from the thank you page, since the other pages wouldn't have anything to send. Give it a try. What can it hurt?
     
    ColeenB, Jun 4, 2009 IP