我为我的iOS-App设置了Google Analytics,它基本上运行正常(屏幕跟踪,购买,...),但安装广告系列跟踪不正常。 我在这里看到一个类似的问题没有解决: Google analytics iOS campaign tracking testing on development
这是我用来实现的指南(在Objective-C中): https://developers.google.com/analytics/devguides/collection/ios/v3/campaigns#general-campaigns
我在Google Analytics信息中心中看到引荐来源安装,但没有安装广告系列。
这是测试网址
我在这里生成的: https://developers.google.com/analytics/devguides/collection/ios/v3/campaigns#url-builder
应该跟踪安装的我的代码如下:
的AppDelegate:
//Method where app parses any URL parameters used in the launch
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
//Track google Analytics URL
GAService.shared.trackURL(url)
//some other handlers here ....
return true/false
}
GAService Singleton:
@objc public class GAService : NSObject {
private let trackID : String = "UA-xxxxxx-x"
var trackGoogleAnalytics : Bool = Constants.Analytics.trackGoogleAnalytics
private let UTM_SOURCE_KEY : String = "xxx"
private let UTM_MEDIUM_KEY : String = "xxx"
private let UTM_CAMPAIGN_KEY : String = "xxx"
var trackUncaughtExceptions : Bool = true
var tracker : GAITracker? = nil
static let shared = GAService()
var UtmSource : String {
get {
if let utm = UserDefaults.standard.string(forKey: UTM_SOURCE_KEY) {
return utm
}
return ""
}
set {
if UserDefaults.standard.string(forKey: UTM_SOURCE_KEY) == nil {
UserDefaults.standard.set(newValue, forKey: UTM_SOURCE_KEY)
UserDefaults.standard.synchronize()
}
}
}
var UtmCampaign : String {
get {
if let utm = UserDefaults.standard.string(forKey: UTM_CAMPAIGN_KEY) {
return utm
}
return ""
}
set {
if UserDefaults.standard.string(forKey: UTM_CAMPAIGN_KEY) == nil {
UserDefaults.standard.set(newValue, forKey: UTM_CAMPAIGN_KEY)
UserDefaults.standard.synchronize()
}
}
}
var UtmMedium : String {
get {
if let utm = UserDefaults.standard.string(forKey: UTM_MEDIUM_KEY) {
return utm
}
return ""
}
set {
if UserDefaults.standard.string(forKey: UTM_MEDIUM_KEY) == nil {
UserDefaults.standard.set(newValue, forKey: UTM_MEDIUM_KEY)
UserDefaults.standard.synchronize()
}
}
}
private override init() {
super.init()
if(trackGoogleAnalytics) {
tracker = GAI.sharedInstance().tracker(withTrackingId: trackID)
tracker!.allowIDFACollection = true
GAI.sharedInstance().trackUncaughtExceptions = trackUncaughtExceptions
GAI.sharedInstance().logger.logLevel = GAILogLevel.error
GAI.sharedInstance().dispatchInterval = 1
}
}
public func trackURL(_ url : URL){
let urlString = url.absoluteString
// setCampaignParametersFromUrl: parses Google Analytics campaign ("UTM")
// parameters from a string url into a Map that can be set on a Tracker.
let hitParams : GAIDictionaryBuilder = GAIDictionaryBuilder()
// Set campaign data on the map, not the tracker directly because it only
// needs to be sent once.
hitParams.setCampaignParametersFromUrl(urlString)
// Campaign source is the only required campaign field. If previous call
// did not set a campaign source, use the hostname as a referrer instead.
if((hitParams.get(kGAICampaignSource) != nil) && (url.host ?? "").length() != 0) {
hitParams.set("referrer", forKey: kGAICampaignMedium)
hitParams.set(url.host, forKey: kGAICampaignSource)
}
let hitParamsDict : [AnyHashable : Any] = hitParams.build() as Dictionary as [AnyHashable : Any]
if(hitParamsDict.count > 0) {
// A screen name is required for a screen view.
let source : String? = hitParams.get(kGAICampaignSource)
let medium : String? = hitParams.get(kGAICampaignMedium)
let campaign : String? = hitParams.get(kGAICampaignName)
if(source != nil || medium != nil || campaign != nil) {
tracker?.set(kGAIScreenName, value: "openUrl")
GAService.shared.UtmSource = source ?? ""
GAService.shared.UtmMedium = medium ?? ""
GAService.shared.UtmCampaign = campaign ?? ""
}
// SDK Version 3.08 and up.
//[tracker send:[[[GAIDictionaryBuilder createScreenView] setAll:hitParamsDict] build]];
let sendDict : [AnyHashable : Any] = GAIDictionaryBuilder.createScreenView().setAll(hitParamsDict).build() as Dictionary as [AnyHashable : Any]
tracker?.send(sendDict)
tracker?.set(kGAIScreenName, value: nil)
}
}
由于我必须为这样的跟踪设置screenName,我将openUrl定义为常量并将其设置为nil之后我发送了字典。
我希望任何人都可以看到我做错了什么
提前谢谢
答案 0 :(得分:0)
我认为Google Analytics文档在这个问题上非常糟糕。如果您仔细查看“广告系列衡量”主要指南中所写的内容,则说明“安装应用后,可能会通过广告系列,网站或其他应用推介推出”谷歌给出了一个自定义网址方案的例子,该方案已经处理完毕。
希望还有另一个指南https://developers.google.com/analytics/solutions/mobile-campaign-deep-link,其中介绍了如何使用深层链接进行广告系列衡量。
因此,如果您想跟踪广告系列衡量标准,则必须为您的应用程序使用通用链接机制或自定义网址方案。
Universal Links机制是首选方式,如果您有后端,因此可以决定在哪里重定向用户:在iTunes或应用程序中。
假设您有一个站点链接 https://example.com/openapp ,可将用户重定向到iTunes Connect。您应该在中插入通用链接地址( https://example.com/openapp ) 生成器https://developers.google.com/analytics/devguides/collection/ios/v3/campaigns#url-builder。
答案 1 :(得分:0)
我在决定导航的深度链接中使用了它:
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
user_role = models.ForeignKey(Roles, on_delete=models.CASCADE)
def __str__(self):
return self.user.username
class Roles(models.Model):
role_title = models.CharField(max_length=30)
role_description = models.CharField(max_length=100)
def get_absolute_url(self):
return reverse('role-create')
def __str__(self) :
return self.role_title
然后我在Google Analytics(分析)上看到了源代码。