开发者

Tracking iPhone on Yahoo Web Analytics using ASIHTTPRequest

开发者 https://www.devze.com 2022-12-27 08:58 出处:网络
I\'m trying to track an event in my app using Yahoo Web Analytics. The code I am using looks like ASIHTTPRequest *yahooTrack = [ASIHTTPRequest requestWithURL:

I'm trying to track an event in my app using Yahoo Web Analytics. The code I am using looks like

ASIHTTPRequest *yahooTrack = [ASIHTTPRequest requestWithURL:
    [NSURL URLWithString:@"http://s.analytics.yahoo.com/p.pl?a=xxxxxxxxxxxxx&js=no&b=yyyyyyyyyyyy&cf6=zzzzzzzzzzz"]];
yahooTrack.didFinishSelector = @selector(statisticsFinished:);
yahooTrack.delegate = self;
[yahooTrack startAsynchronous];

Then the statisticsFinished looks like:

NSLog(@"Cookies: %@", request.requestCookies);
NSLog(@"Redircount: %d", [request redirectCount]);
NSLog(@"Responsecode %d 开发者_StackOverflow社区%@\nMsg: %@", request.responseStatusCode, 
    request.responseStatusMessage, [request responseString]);

And all the information I get back looks correct. Cookies are set, redirectcount is 1 the first time (as it redirects to s.analytics.yahoo.com/itr.pl?.... a normal browser does). Then the redirectcount is 0 for subsequent request until the app is restarted and session cleared. The responseString returns GIF89a.

Even if the data looks correct, Yahoo still won't track. As soon as I call the tracking url directly in my browser it works as expected.

I realize Flurry is a better option, but I'm forced to use Yahoo in this case. Also, using a UIWebView probably would work, but I'm against putting in a webview just for tracking purposes.

Is there any difference in how ASIHTTPRequest and Safari would handle a call to a simple URL as this? Or do you see anything else that could explain why the tracking isn't working?


I finally found the problem. ASIHTTPRequest creates a user-agent based on your applications name, and requests from this user agent is ignored by Yahoo somehow (bug?). As stated in the documentation, you can override the user-agent as follows:

[request addRequestHeader:@"User-Agent" value:@"My-User-Agent-1.0"];

I used the user-agent string of Safari on iPhone, and it worked immediately! BTW; the same problem applies for Android, and the same fix works.

0

精彩评论

暂无评论...
验证码 换一张
取 消