Hi -
we're working on implementing Universal google analytics, but having trouble getting the ga code passed along via custom field to the cart page and checkout page. The way our store works is using a minicart dropdown, so when a customer adds something to the cart, the minicart shows and there they have the option to either view the cart page or go directly to the checkout page. This all seems to be working fine on our dev site, the ga code is added to customfields, but one thing I have noticed is that in our template caching for our production site, the javascript and css files are not being pulled out the way they are on the dev site, I am not sure if that's possibly part of the problem?
Any help would be much appreciated.
Thanks,
Jessica
In your uw.view-cart.js file, try not wrapping that code inside the document.ready call - I think that is causing that block to run after the later blocks within the page, which is overwriting them. They should be fine to run straight away rather than on document.ready.
Doing it this way, the ga custom field is being added, so the transaction can be tracked across the domain switch, but I am getting a type undefined error for the next section of
Yeah - moving it in there would have gotten it working, or I believe simply removing the document.ready call and leaving the code where it was would work as well. The issue was the block inside the document.ready call was resetting the process function event queue, so it was blowing away the ga event that was there previously.
Looking at your page, if I add this using Chrome browser console, it works just fine:
But for some reason, it's failing for your code there. Quite strange! Could you try logging what e is within that function you've written?
What does the console log for 'e' within your function?
So that's the key issue then there - it shouldn't be running twice for a single add to cart action.
Ah actually - I think I found the issue. You changed how/when the GA session is added into the JSON cart - so that needs a slight change, specifically this:
Would become:
Where I have it now, there's still an error being popped, but it's functioning properly otherwise. I don't know why it's going back through that fcc.events.cart.process.add function a second time, but it is because the count is being increased, and when it does, that's when the error of undefined e is triggered.
It's because you're resuming the process event queue from within the preprocess events. Did you copy the function as I said to update it above? While it did pause the preprocess events, it also restarted it from within the success function of the getJSON call.
Awesome! Glad that got it working! Let us know if you bump into anything else.