Hi,
I’m trying to set up the app conversion tracking from Admob. I need to add the two codes snippets:
[self performSelectorInBackground:@selector(reportAppOpenToAdMob) withObject:nil];
// This method requires adding #import <CommonCrypto/CommonDigest.h> to your source file.
- (NSString *)hashedISU {
NSString *result = nil;
NSString *isu = [UIDevice currentDevice].uniqueIdentifier;
if(isu) {
unsigned char digest[16];
NSData *data = [isu dataUsingEncoding:NSASCIIStringEncoding];
CC_MD5([data bytes], [data length], digest);
result = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[0], digest[1],
digest[2], digest[3],
digest[4], digest[5],
digest[6], digest[7],
digest[8], digest[9],
digest[10], digest[11],
digest[12], digest[13],
digest[14], digest[15]];
result = [result uppercaseString];
}
return result;
}
- (void)reportAppOpenToAdMob {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // we're in a new thread here, so we need our own autorelease pool
// Have we already reported an app open?
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
NSString *appOpenPath = [documentsDirectory stringByAppendingPathComponent:@"admob_app_open"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:appOpenPath]) {
// Not yet reported -- report now
NSString *appOpenEndpoint = [NSString stringWithFormat:@"http://a.admob.com/f0?isu=%@&md5=1&app_id=%@",
[self hashedISU], @"<APPLE ITUNES ID>"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:appOpenEndpoint]];
NSURLResponse *response;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if((!error) ([(NSHTTPURLResponse *)response statusCode] == 200) ([responseData length] > 0)) {
[fileManager createFileAtPath:appOpenPath contents:nil attributes:nil]; // successful report, mark it as such
NSLog(@"App download successfully reported.");
} else {
NSLog(@"WARNING: App download not successfully reported. %@", [NSString stringWithData:responseData encoding:NSUTF8StringEncoding]);
}
}
[pool release];
}
Here is my problem, I know Unity well but with Xcode, I’ve got no clue what’s going on… I looked online to find where to place them and how to do it.
Atm, I placed them in iPhone_target2AppDelegate.m
like this:
//
// iPhone_target2AppDelegate.m
// iPhone-target2
//
// Created by Renaldas on 8/22/08.
// Copyright __MyCompanyName__ 2008. All rights reserved.
//
#import "iPhone_target2AppDelegate.h"
#import <CommonCrypto/CommonDigest.h>
@implementation iPhone_target2AppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[self performSelectorInBackground:@selector(reportAppOpenToAdMob) withObject:nil];
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
// This method requires adding #import <CommonCrypto/CommonDigest.h> to your source file.
- (NSString *)hashedISU {
NSString *result = nil;
NSString *isu = [UIDevice currentDevice].uniqueIdentifier;
if(isu) {
unsigned char digest[16];
NSData *data = [isu dataUsingEncoding:NSASCIIStringEncoding];
CC_MD5([data bytes], [data length], digest);
result = [NSString stringWithFormat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
digest[0], digest[1],
digest[2], digest[3],
digest[4], digest[5],
digest[6], digest[7],
digest[8], digest[9],
digest[10], digest[11],
digest[12], digest[13],
digest[14], digest[15]];
result = [result uppercaseString];
}
return result;
}
- (void)reportAppOpenToAdMob {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // we're in a new thread here, so we need our own autorelease pool
// Have we already reported an app open?
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
NSString *appOpenPath = [documentsDirectory stringByAppendingPathComponent:@"admob_app_open"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:appOpenPath]) {
// Not yet reported -- report now
NSString *appOpenEndpoint = [NSString stringWithFormat:@"http://a.admob.com/f0?isu=%@&md5=1&app_id=%@",
[self hashedISU], @"<APPLE ITUNES ID>"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:appOpenEndpoint]];
NSURLResponse *response;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if((!error) ([(NSHTTPURLResponse *)response statusCode] == 200) ([responseData length] > 0)) {
[fileManager createFileAtPath:appOpenPath contents:nil attributes:nil]; // successful report, mark it as such
NSLog(@"App download successfully reported.");
} else {
NSLog(@"WARNING: App download not successfully reported. %@", [NSString stringWithData:responseData encoding:NSUTF8StringEncoding]);
}
}
[pool release];
}
@end
As you can see I’ve added the #import <CommonCrypto/CommonDigest.h> on the top…
When I launch the app, I’ve got no feedback. It s supposed to say:
“App download successfully reported.” or this “WARNING: App download not successfully reported.” But I don’t get anything at all.
Does anyone could help me out on how to set up this conversion tracking system ? It seems pretty easy but I don’t have the knowledge in Xcode to fully understand what I’m doing in it… ![]()
Thanks for the help
BooBi
P.S. I took off my apple itunes ID from the code posted but not on the code I use.