Name
Name

Reputation: 21

Google Analytics doesn't show purchases but events

I have a problem with Google Analytics for Android. I'm trying to use Ecommerce Tracking but it doesn't work. I'm sending an hit and Eclipse shows me in the LogCat

Sending hit to service  ...

Google Analytics shows me under "Realtime" the event (category, action, label) but under "Conversions" not the purchased product.

Product product = new Product()
.setName("myproduct");

tracker
.send(new HitBuilders.EventBuilder()
.setCategory(category)
.setAction(action)
.setLabel(label)
.addProduct(product)
.setProductAction(new ProductAction(ProductAction.ACTION_PURCHASE))
.build());

And yes, I have activated E-Commerce under the Data View Settings

What I'm doing wrong?

Upvotes: 2

Views: 1205

Answers (1)

Saxon Druce
Saxon Druce

Reputation: 17624

The code below works for me.

Also note that Conversions includes both Goals and Ecommerce. The Realtime section only shows Goals. For Ecommerce you have to wait a while until the event appears in the main Conversions -> Ecommerce section (about 15 minutes or more).

// Logs a purchase event to Google analytics, for ecommerce tracking.
private void logGooglePurchaseEvent(String transactionId, String productId)
{
    // Look up the product's price.
    double price = getProductPrice(productId);
    // Look up the product's currency.
    String currency = getProductPriceCurrency(productId);

    // Set up the product.
    Product product = new Product()
        .setId(productId)
        .setName(productId)
        .setCategory("iap")
        .setPrice(price)
        .setQuantity(1);

    // Set up the purchase action.
    ProductAction productAction = 
        new ProductAction(ProductAction.ACTION_PURCHASE)
            .setTransactionId(transactionId)
            .setTransactionAffiliation("Google Play")
            .setTransactionRevenue(price);

    // Create the builder, which combines the purchase with the product.
    HitBuilders.EventBuilder builder = 
        new HitBuilders.EventBuilder();
    builder.setProductAction(productAction).addProduct(product);
    builder.setCategory("transaction").setAction("purchase");

    // Create the analytics tracker.
    GoogleAnalytics analytics = GoogleAnalytics.getInstance(_context);
    Tracker tracker = analytics.newTracker(
        getGoogleAnalyticsPropertyId());

    // Send the event, specifying the currency.
    tracker.set("&cu", currency);
    tracker.send(builder.build());
}

Upvotes: 1

Related Questions