This project has moved and is read-only. For the latest updates, please go here.

From trial to paid

Jul 15, 2013 at 2:59 PM
Hi,

Does anyone know how to correctly track a sale of a trial app to a paid app?

Best,

Mark Monster
Jul 16, 2013 at 2:01 AM
Here's a code snippet for WP to help track a product purchase:
try
{
    var receipt = await CurrentApp.RequestAppPurchaseAsync(true);
    if (CurrentApp.LicenseInformation.IsActive)
    {
        var listing = await CurrentApp.LoadListingInformationAsync();
        var transaction = GoogleAnalytics.TransactionBuilder.GetAppPurchaseTransaction(listing, receipt);
        GoogleAnalytics.EasyTracker.GetTracker().SendTransaction(transaction);
    }
}
catch (Exception ex)
{
    GoogleAnalytics.EasyTracker.GetTracker().SendException(ex.StackTrace, false);
}
Jul 18, 2013 at 1:24 PM
Hi Tim,

Thanks for the code, this is exactly what I like to see.

I must admit I didn't know about CurrentApp.RequestAppPurchaseAsync.

Best,

Mark Monster
Jul 20, 2013 at 9:07 PM
Hi Tim,

The above code doesn't run in Windows Phone sadly. It compiles, but runtime it gives a NotImplementedException. Nice :-(.

Best,

Mark Monster
Jul 22, 2013 at 11:23 PM
Hi Mark, interesting. Maybe this only works with in-app purchases using RequestProductPurchaseAsync. I thought I had tried this but now I'm not 100% sure. Note for anyone using this: you need to use MockIAPLib when debugging.

Alternatively you can use a more manual approach:
double cost = 1.99;
long costInMicrons = (long)(cost * 1000000);
var transaction = new GoogleAnalytics.Transaction("01234", costInMicrons);
var item = new GoogleAnalytics.TransactionItem("myproduct", "My Product", costInMicrons, 1);
transaction.Items.Add(item);

GoogleAnalytics.EasyTracker.GetTracker().SendTransaction(transaction);