/*
* Copyright 2015-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
using System.Collections;
using System;
using Amazon.MobileAnalytics.MobileAnalyticsManager.Internal;
using System.Globalization;
namespace Amazon.MobileAnalytics.MobileAnalyticsManager
{
///
/// Represents purchase event in your application. The event attribute must be set by user.
///
/// The example below shows how to use MonetizationEvent
///
/// MonetizationEvent monetizationEvent = new MonetizationEvent();
///
/// monetizationEvent.Quantity = 3.0;
/// monetizationEvent.ItemPrice = 1.99;
/// monetizationEvent.ProductId = "ProductId123";
/// monetizationEvent.ItemPriceFormatted = "$1.99";
/// monetizationEvent.Store = "Apple";
/// monetizationEvent.TransactionId = "TransactionId123";
/// monetizationEvent.Currency = "USD";
///
/// analyticsManager.RecordEvent(monetizationEvent);
///
///
///
public class MonetizationEvent : CustomEvent
{
// event type
private const string PURCHASE_EVENT_NAME = "_monetization.purchase";
// metric name
private const string PURCHASE_EVENT_QUANTITY_METRIC = "_quantity";
private const string PURCHASE_EVENT_ITEM_PRICE_METRIC = "_item_price";
// attribute name
private const string PURCHASE_EVENT_PRODUCT_ID_ATTR = "_product_id";
private const string PURCHASE_EVENT_ITEM_PRICE_FORMATTED_ATTR = "_item_price_formatted";
private const string PURCHASE_EVENT_STORE_ATTR = "_store";
private const string PURCHASE_EVENT_TRANSACTION_ID_ATTR = "_transaction_id";
private const string PURCHASE_EVENT_CURRENCY_ATTR = "_currency";
///
/// Constructor of
///
public MonetizationEvent() : base(PURCHASE_EVENT_NAME)
{
}
// metrics
///
/// Sets the quantity.
///
/// The quantity. For example, 1.0
public double? Quantity { get;set; }
///
/// Sets the item price.
///
/// The item price. For example, 3.0
public double? ItemPrice { get;set; }
// attributes
///
/// Sets the product identifier.
///
/// The product identifier. For example, ProductId123.
public string ProductId { get;set; }
///
/// Sets the item price formatted.
///
/// The item price formatted. For example, $1.99
public string ItemPriceFormatted { get;set; }
///
/// Sets the store.
///
/// The store. For example, AppStore.
public string Store { get;set; }
///
/// Sets the transaction identifier.
///
/// The transaction identifier. For example, TransactionId123.
public string TransactionId { get;set; }
///
/// Sets the currency.
///
/// The currency.
public string Currency { get;set; }
///
/// Converts to mobile analytics model event.
///
/// The to mobile analytics model event.
/// Session.
internal override Amazon.MobileAnalytics.Model.Event ConvertToMobileAnalyticsModelEvent(Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session session)
{
if(Quantity != null)
{
this.AddMetric(PURCHASE_EVENT_QUANTITY_METRIC,Convert.ToDouble(Quantity, CultureInfo.InvariantCulture));
}
if(ItemPrice != null)
{
this.AddMetric(PURCHASE_EVENT_ITEM_PRICE_METRIC, Convert.ToDouble(ItemPrice, CultureInfo.InvariantCulture));
}
if(!string.IsNullOrEmpty(ProductId))
{
this.AddAttribute(PURCHASE_EVENT_PRODUCT_ID_ATTR,ProductId);
}
if(!string.IsNullOrEmpty(ItemPriceFormatted))
{
this.AddAttribute(PURCHASE_EVENT_ITEM_PRICE_FORMATTED_ATTR,ItemPriceFormatted);
}
if(!string.IsNullOrEmpty(Store))
{
this.AddAttribute(PURCHASE_EVENT_STORE_ATTR,Store);
}
if(!string.IsNullOrEmpty(TransactionId))
{
this.AddAttribute(PURCHASE_EVENT_TRANSACTION_ID_ATTR,TransactionId);
}
if(!string.IsNullOrEmpty(Currency))
{
this.AddAttribute(PURCHASE_EVENT_CURRENCY_ATTR,Currency);
}
return base.ConvertToMobileAnalyticsModelEvent(session);
}
}
}