Product Revenue versus Revenue in Google Analytics - google-analytics

On our online shopping cart, some products are not being attributed to the "Product Revenue" metric in Google Analytics. I understand that if a product is not assigned to a product category, it will be counted under "Revenue" but not "Product Revenue". In this case, it appears that the products are indeed assigned properly:
_gaq.push(['sec._addTrans',
'91195800', // transaction ID - required
'nature', // affiliation or store name
'81.01', // total - required
'0', // tax
'0', // shipping
'Stoney Creek', // city
'ON', // state or province
'CA' // country
_gaq.push(['sec._addItem',
'91195800', // transaction ID - required
'ADULT - ADV', // SKU/code - required
'Product A', // product name
'Attraction Pass',
'49.946902654867', // unit price - required
'1' // quantity - required
]);
_gaq.push(['sec._addItem',
'91195800', // transaction ID - required
'UNKNOWN', // SKU/code - required
'Product B', // product name
'Attraction Pass',
'6.9911504424779', // unit price - required
'1' // quantity - required
]);
_gaq.push(['sec._addItem',
'91195800', // transaction ID - required
'ADULT - ADV', // SKU/code - required
'Product C', // product name
'Attraction Pass',
'14.752212389381', // unit price - required
'1' // quantity - required
]);
I realize there is a second error here in that the unit prices do not include tax, where the total transaction value does, so our two totals won't match there. But the difference right now is far more than just the tax.
For example, yesterday we are seeing $3,299.54 in Product Revenue but $3,932.79 in Revenue. The tax difference would only be $428.94. These are all ticket goods so no shipping costs involved.
I can actually find some of these transactions in our shopping cart backend, where I see 4 x Product A, 4 x Product B in a transaction, but Google Analytics is showing only 4 x Product A for that transaction. The Revenue metric is correct, but the Product Revenue is wrong--clicking into the transaction the Product B's are just missing.
I obviously can't go back in time to check the source code when that customer checked out, but the code above is from a test today. Unfortunately the transaction has yet to show up in GA to see what was counted and what wasn't, but is there something in that code there that would cause an issue?
Edit: The transaction is now showing in Google Analytics and I can confirm that in the above code, Product A did not get counted as an actual product. Does it matter that the SKU is the same between those two items in the code? Would that cause GA to overwrite Product A with Product C because of the same SKU?

Figured this out. SKUs must be unique. So, in my example, the third product is overwriting the first product in this transaction.

Related

Huge discrepancy between Revenue and Product Revenue

I'm seeing a big difference between the reported Revenue and the Product Revenue on transactions. For example, this is what I see for Revenue for a transaction:
And this is the (correct) amount that shows up when I click into that Transaction ID.
The Revenue of the transaction and the Product Revenue are two differents metrics and comes from 2 differents parts of the code. Let me explain you what is maybe happening.
This is the transaction code for the enhanced ecommerce, but it can happens in all the versions of the ecommerce snippet
ga('ec:addProduct', { // Provide product details in an productFieldObject.
'id': 'P12345', // Product ID (string).
'name': 'Android Warhol T-Shirt', // Product name (string).
'category': 'Apparel', // Product category (string).
'brand': 'Google', // Product brand (string).
'variant': 'black', // Product variant (string).
'price': '29.20', // Product price (currency). <-- UnitPrice
'coupon': 'APPARELSALE', // Product coupon (string).
'quantity': 1 // Product quantity (number). <--Quantity
});
ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
'id': 'T12345', // (Required) Transaction id (string).
'affiliation': 'Google Store - Online', // Affiliation (string).
'revenue': '37.39', // Revenue (currency). <<- Revenue
'tax': '2.85', // Tax (currency).
'shipping': '5.34', // Shipping (currency).
'coupon': 'SUMMER2013' // Transaction coupon (string).
});
The product Revenue is based on the multiplication of the Quantity * UnitPrice (calculated in each transaction) and the Transaction Revenue belongs to the 'purchase' object.
Google Analytics dosent matter any logic, for example, you can have in one transaction a product price of $99.99 with Quantity of 2 and in the same transaction declarate the reveue as $2 and it's ok for Analytics. And we know that is not right.
So, you need to make that number match, The common mistakes here are:
Transactions apply Discount -> Sum of product dont have discount applied
Transactions don't apply Discount -> Sum of product have discount applied
Transaction is A -> Sum of Product is C
Google does not add product values up - instead the product revenue and the transaction revenue is passed to GA via different variables in the tracking code, and the reports show the respective variable values.
So I guess somebody passed in the wrong value (I vaguely suspect a wrong decimal separator). You need to check your transaction code.

Can I set a custom dimention within setAction in ec.js (Google Analytics)?

I've been searching Google but really there is no answer. Perhaps any of you guys here know: would the code below work:
ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
'id': 'T12345', // (Required) Transaction id (string).
'affiliation': 'Google Store - Online', // Affiliation (string).
'revenue': '37.39', // Revenue (currency).
'tax': '2.85', // Tax (currency).
'shipping': '5.34', // Shipping (currency).
'coupon': 'SUMMER2013', // Transaction coupon (string).
'dimension1': 'custom1',
'dimension2': 'custom2'
});
I mean if custom dimension can be set here within the setAction or not?
Thanks for your help.
Custom dimensions are set either in hit scope (referring to individual actions), product scope (with Enhanced E-Commcerce, so to speak a special case of hit scope), session scope (i.e. referring to all pageview within a visit) or user scope (referring to all sessions of a recurring user).
There is no "setAction"-scope or anything like it. I haven't tested the code and it might even work by accident, but even so it would still end up in hit/session/user scope, depending on the backend settings for your dimensions and thus would be pointless.

How to show correct tax on basket (BEFORE checkout)?

I have a simple problem.
I have set up multiple tax rates for different countries.
However, on the basket page - when not having visited the checkout page so far - it shows the tax from the base country.
In my case: I have a shop based in AT. I have set up taxes for AT and CH.
If a user visits with a Switzerland IP, I restrict the country list to just Switzerland, and set a PHP variable. Nevertheless the country isn't in the woocommerce_countries anymore, WC calculates the taxes with the base country tax setting.
See those images:
taxes in basket -
taxes on checkout
I want to show the correct tax BEFORE the checkout.
I already figured out that the correct taxes are shown when the user has chosen a country on the checkout page, and a "$woocommerce->customer" node is available.
But I struggle to make that happen.
Anyone got an idea how to do this?
Here's my plugin code which does not work:
define('USERCOUNTRY', get_country_proper()); // returns 'CH'
$customer = new WC_Customer();
WC()->customer->set_country(USERCOUNTRY);
Result:
Fatal error: Call to a member function get() on a non-object in wp-content/plugins/woocommerce/includes/class-wc-customer.php on line 27
Update:
The tax which will be used on the CART page (before entering a country on the CHECKOUT) is used here:
Woocommerce -> Settings -> Tax -> Default Customer Address: [Shop Base country | none]
http://docs.woothemes.com/document/setting-up-taxes-in-woocommerce/
OK, can I alter this via script?
Thanks for any help.
There is, actually, a hook for that.
// this is used for taxing:
add_filter('woocommerce_countries_base_country', 'set_base_to_usercountry', 1, 1);
// and this is used for shipping:
add_filter('woocommerce_customer_default_location', 'set_base_to_usercountry', 1, 1);
function set_base_to_usercountry($country) {
$country = USERCOUNTRY; // comes from a geoIP lookup in my case.
return $country;
}
// and this is also needed not to have trouble with the "modded_tax".
// (which looks like rounding issues, but is a tax conversion issue.)
add_filter('woocommerce_customer_taxable_address', 'alter_taxable_address', 1, 1);
function alter_taxable_address($address) {
// $address comes as an array with 4 elements.
// first element keeps the 2-digit country code.
$address[0] = USERCOUNTRY;
return $address;
}

woocommerce update sale price

I currently have a form where the admin can bulk update sale prices of products within one screen.
When the form is submitted i simply use update_post_meta like this:
update_post_meta($id,'_sale_price', 'new sale price here');
This updates the _sale_price meta key. When i go into the admin to check this, the new sale price has been inserted. When i view the product on the front end, the item is not marked as on sale. I have to go back in and re-save the product.
My question is, does woocommerce add some other meta_key to mark the product as on sale? I have had a dig round in the database for all the custom fields inserted, but can only see _sale_price.
Any help would be greatly appreciated
Having a look at the Product abstract class in WooCommerce the following php code gets whether or not the product is on sale:
return ( $this->sale_price != $this->regular_price && $this->sale_price == $this->price );
Which seems to indicate that the _price has to be the same as the sale_price in order for it to be classed as on sale. So just
update_post_meta($id, '_price', 'new sale price here too');
as well as the code in your question and it should work.

How to view the city/state/country in google analytice ecommerce tracking?

I want to use google analytice ecommerce for some requirements.
So, I used the following code snippet from google.
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'1234', // order ID - required
'Womens Apparel', // affiliation or store name
'28.28', // total - required
'1.29', // tax
'15.00', // shipping
'San Jose', // city
'California', // state or province
'USA' // country
]);
_gaq.push(['_addItem',
'1234', // order ID - necessary to associate item with transaction
'DD44', // SKU/code - required
'T-Shirt', // product name
'Olive Medium', // category or variation
'11.99', // unit price - required
'1' // quantity - required
]);
_gaq.push(['_trackTrans']);
So with this code sample my transactions are getting tracked.
But in my google analytics profile, I'm not seeing the city, state, country. Though other details like order_id, shipping, etc SKU are getting tracked.
Please let me know if you have any idea on this.
Thanks,
Uttam
All other variables within the addTrans method are optional.
The affiliate field is not required, and was removed from the Google
Analytics Ecommerce reports. You can still use the affiliate field for
custom reports and filtering.
Tax and shipping appear in the transactions report if you have access
to those variables.
The city, state, and country are currently not being used by Google
Analytics, but the information is still being collected. You can
however use these fields within the profile filters if you have a use
for them.
Source: http://www.roirevolution.com/blog/2009/05/stressing_about_your_ga_ecommerce.php

Resources