pista StoreKit acquisto Eventi
Quando un acquisto avviene, inviarti un datapoint (Traccia qui ...)
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transation in transactions {
switch transation.transactionState {
case .purchased:
queue.finishTransaction(transation)
// Track here...
case .purchasing: break
case .restored: break
case .deferred: break
case .failed: break
}
}
}
biblioteche Leverage
Usa analisi. Sostituisci il commento // Track here...
in alto con uno dei blocchi qui sotto. Elenco non esaustivo in ordine alfabetico:
Accengage
NSString *currencyCode = [<SKProduct.priceLocale>
objectForKey:NSLocaleCurrencyCode];
BMA4SPurchasedItem* item =
[BMA4SPurchasedItem itemWithId(t.payment.productIdentifier)
label:t.payment.productName
category:<product.type>
price:@(<SKProduct.price>)
quantity:t.payment.quantity
];
[BMA4STracker trackPurchaseWithId:transaction.identifier
currency:currencyCode
items:@[item]];
Branch
NSDictionary *state = @{
@"itemId": @(t.payment.productIdentifier),
@"price": <SKProduct.price>,
@"itemName": <SKProduct.name>,
@"currency":currencyCode };
[[Branch getInstance] userCompletedAction:@"purchase" withState:state];
Fabric (Crashlytics)
NSString *currencyCode = [<SKProduct.priceLocale>
objectForKey:NSLocaleCurrencyCode];
[Answers logPurchaseWithPrice:<SKProduct.price>
currency:currencyCode
success:@YES
itemName:<product name>
itemType:@"Purchase"
itemId:@(t.payment.productIdentifier)
customAttributes:@{}];
FlightRecorder
FlightRecorder.sharedInstance().trackEventWithCategory(
"Actions",
action: "Purchase",
label: "productIdentifier",
value: t.payment.productIdentifier)
Flurry Analytics
let properties = ["productIdentifier":t.payment.productIdentifier]
Flurry.logEvent("Purchase", withParameters: properties)
Google Analytics
#import "GAI.h"
#import "GAIDictionaryBuilder.h"
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
NSString *currencyCode = [<SKProduct.priceLocale>
objectForKey:NSLocaleCurrencyCode];
[tracker send:[[GAIDictionaryBuilder
createItemWithTransactionId:transactionIdentifier
name:<product.localizedTitle>
sku:t.payment.productIdentifier
category:@"Purchase"
price:<SKProduct.price>
quantity:@(t.payment.quantity)
currencyCode:currencyCode]
build]];
Vedi In-app purchase tracking with Google Analytics iOS SDK.
Heap Analytics
[Heap track:@"Purchase"
withProperties:@{@"productIdentifier":@(t.payment.productIdentifier)}
];
MixPanel Analytics (*)
Mixpanel.sharedInstance().track("Purchased",
properties: ["productIdentifier":transation.payment.productIdentifier])
properties:@{@"productIdentifier":@(t.payment.productIdentifier)};
(*) Fornisce il supporto per la segnalazione WiFi (permette di rinviare tutti i rapporti fino a quando rete WiFi è disponibile, per non utilizzare dati cellulari). Vedi mixpanelWillFlush
qui sotto.
Parse.com
NSDictionary *dimensions =
@{@"productIdentifier":@(t.payment.productIdentifier)};
[PFAnalytics trackEvent:@“Purchase” dimensions:dimensions];
Invia una e-mail da un server
POST
acquisto a un URL, e hanno a loro volta il server che si invia una mail o altra notifica.
applicazione iOS utilizzando URLSession
:
if let url = URL(string: "https://<yoursite>/php/purchase.php") {
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody =
"{\"productIdentifier\":\"\(transaction.payment.productIdentifier)\"}"
.data(using: .utf8)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
let task = URLSession.shared.dataTask(with: request as URLRequest,
completionHandler: {_,_,_ in })
task.resume()
}
purchase.php
e-mail del mittente:
<?php
try {
header('Content-type: application/json');
$to = '[email protected]';
$subject = 'Purchase';
$message = $_POST['productIdentifier'];
$headers = "From: " . $to . "\n";
@mail($to, $subject, $message, $headers)
} catch (Exception $e) {}
?>
► Trova questa soluzione su GitHub e ulteriori dettagli su Swift Recipes.
Ovviamente la tua app lo sa. Potresti inviare un messaggio al tuo server. Ma perché? Cosa c'è che non va sapendo una volta al giorno? – rmaddy
Quando dici "invia un messaggio al tuo server", intendi qualcosa come Parse o qualcosa di diverso? Si prega di elaborare. – Creagen
Inoltre, è bello ricevere notifiche quando vendi qualcosa. Un business online riceve email ogni volta che ottengono una vendita. Mi piacerebbe, ma per un'app/vendita in-app. – Creagen