开发者

Trying to link http://www.example.com to my shopping cart on https://secure.example.com

开发者 https://www.devze.com 2022-12-24 18:03 出处:网络
Heres my saga - I\'m trying to link http://www.example.com to my shopping cart on https://secure.example.com, but it doesnt seem to be linking correctly.

Heres my saga - I'm trying to link http://www.example.com to my shopping cart on https://secure.example.com, but it doesnt seem to be linking correctly.

Heres my code:

<!--Google Analytics -->
<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-125xxxxx-1");
//start cart link
pageTracker._setDomainName(".example.com");
pageTracker._setAllowHash(false);
//end cart link
pageTracker._trackPageview();
} catch(err) {}</script>
<!--Google Analytics -->

Notice the two lines:

pageTracker._setDomainName(".example.com");
pageTracker._setAllowHash(false);

I added the first line so I could share the cookies between site and cart, and added the setAllowHash to make sure it used the utm values from the cookie, and didnt 'recreate' them when I entered https://secure.example.com.

Using firecook开发者_如何学编程ie, it does indeed share the same cookie between site and cart, and the cookies domain is 'example.com'.

I'm pretty sure though that if it was working right, all my utmz, utma values etc should be copied over and remain the same, but they're changing. I've copied all the params that are being sent to google analytics and pasted then below. It shows what is happening from my homepage, to my product page, then into my cart all the way to the page before ordering. ( I can't practically test the final page myself without buying something, so I'll post the code from our confirmation page later if needed.)

Here goes:

===============================================================
HOMEPAGE - http://www.example.com
----------------------------------------------------------------------------------------
utmac UA-125xxxxx-1
utmcc __utma=1.1920057171.1269446996.1269446996.1269446996.1;+__utmz=1.1269446996.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
utmcs UTF-8
utmdt GSM Cell Phone Rental from example
utmfl 10.0 r45
utmhid 69978133
utmhn www.example.com
utmje 1
utmn 1806413990
utmp /
utmr -
utmsc 24-bit
utmsr 1280x800
utmul en-gb
utmwv 4.6.5

PRODUCT PAGE - http://www.example.com/products/international-cell-phone-purchase/
----------------------------------------------------------------
utmac UA-125xxxxx-1
utmcc __utma=1.1920057171.1269446996.1269446996.1269446996.1;+__utmz=1.1269446996.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
utmcs UTF-8
utmdt example | International Cell Phones
utmfl 10.0 r45
utmhid 276151647
utmhn www.example.com
utmje 1
utmn 155808433
utmp /products/international-cell-phone-purchase/
utmr 0
utmsc 24-bit
utmsr 1280x800
utmul en-gb
utmwv 4.6.5

CART STAGE 1 - https://secure.example.com/checkout/viewbasket.php
------------------------------------------------
utmac UA-125xxxxx-1
utmcc __utma=60286578.994269564.1269447144.1269447144.1269447144.1;+__utmz=60286578.1269447144.1.1.utmcsr=example.com|utmccn=(referral)|utmcmd=referral|utmcct=/products/international-cell-phone-purchase/;
utmcn 1
utmcs UTF-8
utmdt Your Cart
utmfl 10.0 r45
utmhid 1802074903
utmhn secure.example.com
utmje 1
utmn 1621444199
utmp 1-reviewcart
utmr http://www.example.com/products/international-cell-phone-purchase/
utmsc 24-bit
utmsr 1280x800
utmul en-gb
utmwv 4.6.5

CART STAGE 2 - https://secure.example.com/checkout/docheckout.php
------------------------------------------------
utmac UA-125xxxxx-1
utmcc __utma=60286578.994269564.1269447144.1269447144.1269447144.1;+__utmz=60286578.1269447144.1.1.utmcsr=example.com|utmccn=(referral)|utmcmd=referral|utmcct=/products/international-cell-phone-purchase/;
utmcs UTF-8
utmdt Checkout
utmfl 10.0 r45
utmhid 871670520
utmhn secure.example.com
utmje 1
utmn 1153927228
utmp 2-checkout
utmr 0
utmsc 24-bit
utmsr 1280x800
utmul en-gb
utmwv 4.6.5

CART STAGE 3 - https://secure.example.com/checkout/doreview.php
----------------------------------------------
utmac UA-125xxxxx-1
utmcc __utma=60286578.994269564.1269447144.1269447144.1269447144.1;+__utmz=60286578.1269447144.1.1.utmcsr=example.com|utmccn=(referral)|utmcmd=referral|utmcct=/products/international-cell-phone-purchase/;
utmcs UTF-8
utmdt Checkout
utmfl 10.0 r45
utmhid 1731598159
utmhn secure.example.com
utmje 1
utmn 1442257710
utmp 3-checkoutreview
utmr 0
utmsc 24-bit
utmsr 1280x800
utmul en-gb
utmwv 4.6.5
===============================================================

As you can see, the utma values are not being preserved, so it looks like a config issue. I've studied the help does but none of the cases seem to fit mine.

I hope someone can offer help on this, its been an ongoing problem of mine for a while, and would be good to finally get rock-solid reliable analytics set up.


(I'm assuming you have enabled e-commerce reporting from your Profile Settings.)

I believe you are missing some boilerplate (more on that in a moment). Additionally, the two lines you mention in the text of your question (between "start cart link" and "end cart link" are not necessary.

After your call to _trackPageview, you need three additional lines, two of those lines update arrays that hold transaction and store item data, respectively, and a final line to call _trackTrans(). That's the call you need to send your information to the GA server:

So after you call _trackPageview, insert these three lines:

pageTracker._addTrans();        // initializes a trans obj; stores trans data     
pageTracker._addItem();         // array holding data for each item in the cart
pageTracker._trackTrans();      // confirms purchase, finalizes transaction 

Nothing is passed in the call to _trackTrans, but you will pass in arguments for the two function calls above. Keep in mind that the argument lists for both functions are matched by position, so it's best to use placeholders for parameters you don't use. Here's a link to a page showing the parameter lists.


It looks like you're missing the following lines in the JS from the cart subdomain:

pageTracker._setDomainName(".example.com");
pageTracker._setAllowHash(false);

The setDomainName sets the cookie domain, and the setAllowHash(false) turns the domain hash at the start of the utma cookie to '1' rather than a numeric hash of the domain name - it's not really required in this case since the shopping cart is on the same base domain as the main site, but if you change it all your previous user cookies won't match.

Don't get too excited by the cookie values (if you fix things, you'll see both the old & new cookies), test with the Firebug Net Panel to see what's really going back to GA.


I've actually got it working now using the following:

<!--Google Analytics Asynchronous Code -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(
    ['_setAccount', 'UA-xxxxxxxx-1'],
    ['_setDomainName', '.domain.com'],
    ['_trackPageview']
  );

  (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>
<!--Google Analytics Asynchronous Code END-->
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号