juriansluiman / SlmGoogleAnalytics

A ZF2 module to track pages, events and ecommerce transactions with Google Analytics
Other
40 stars 20 forks source link

Items with same SKU causes troubles #3

Closed juriansluiman closed 12 years ago

juriansluiman commented 12 years ago

From the Google Analytics api docs:

If a transaction contains multiple items and the SKU is not supplied for every item, a GIF request is sent only for the last item added to the transaction for which a SKU is provided. In addition, if your inventory has different items with the same SKU, and a visitor purchases both of them, you will receive data for only the most recently added. For this reason, you should make sure that each item you offer has a unique SKU.

This is currently not solved by SlmGoogleAnalytics:

use SlmGoogleAnalytics\Analytics\Ecommerce;

$trans = new Transaction;
$trans->setId(321);

$item = new Item;
$item->setSku(123);
$item->setPrice(100);
$item->setQuantity(1);
$trans->addItem($item);

$item = new Item;
$item->setSku(123);
$item->setPrice(100);
$item->setQuantity(1);
$trans->addItem($item);

This results in:

_addItem("321", "123", "", "", "100", "1");
_addItem("321", "123", "", "", "100", "1");

While this is expected:

_addItem("321", "123", "", "", "100", "2");

This should be handled inside the API. Expectation: the second, third, ... nth item with the same sku does only alter quantity and nothing else. If the item has another price, product name or category this will not be taken into account. Possibly we could set a flag for this exception_on_sku_overwrite.