goadmob

package
v1.2.122 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Google admob data Api

Admob API 授权

官方调试平台(授权 获取Token 访问)

https://developers.google.com/oauthplayground/
1 把 redirect_uri 改为自己的服务器地址
https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=https%3A%2F%2Fbangbox.jidianle.cc&prompt=consent&response_type=code&client_id=&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadmob.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadmob.report&access_type=offline
跳转后选择权限 需要授权账号
2 授权后会返回 code
3 获取AccessToken 和 RefreshToken
4 需求

https://admob.googleapis.com/v1/accounts/pub-4328354313035484/networkReport:generate

curl -X POST \
      https://admob.googleapis.com/v1/accounts/pub-XXXXXXXX/networkReport:generate \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer token" \
      -H "X-Goog-AuthUser": "0" \
      --data @- << EOF
{
 "report_spec": {
   "date_range": {
     "start_date": {"year": 2024, "month": 4, "day": 1},
     "end_date": {"year": 2024, "month": 4, "day": 2}
   },
   "dimensions": ["DATE"],
   "metrics": ["CLICKS", "AD_REQUESTS", "IMPRESSIONS", "ESTIMATED_EARNINGS"],
   "dimension_filters": [{"dimension": "COUNTRY", "matches_any": {"values": ["US"]}}],
   "sort_conditions": [{"metric":"CLICKS", order: "DESCENDING"}],
   "localization_settings": {"currency_code": "USD", "language_code": "en-US"}
 }
}
EOF
[ {
  "header" : {
    "dateRange" : {
      "startDate" : {
        "year" : 2024,
        "month" : 8,
        "day" : 20
      },
      "endDate" : {
        "year" : 2024,
        "month" : 8,
        "day" : 21
      }
    },
    "localizationSettings" : {
      "currencyCode" : "USD"
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~1283901700",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AD"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "0"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "238"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~1283901700",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AE"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "22"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "1427375"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~2152486667",
        "displayLabel" : "VPN - biubiuVPN Fast & Secure"
      },
      "COUNTRY" : {
        "value" : "AE"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "223"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "7850960"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~7713423190",
        "displayLabel" : "biubiuVPN : VPN"
      },
      "COUNTRY" : {
        "value" : "AE"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "71"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "4050666"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~8600583746",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AE"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "259"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "6430629"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~1283901700",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AF"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "0"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "3914"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~2152486667",
        "displayLabel" : "VPN - biubiuVPN Fast & Secure"
      },
      "COUNTRY" : {
        "value" : "AF"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "13"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "127095"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~7713423190",
        "displayLabel" : "biubiuVPN : VPN"
      },
      "COUNTRY" : {
        "value" : "AF"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "2"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "60361"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~8600583746",
        "displayLabel" : "JumpJumpVPN- Fast & Secure VPN"
      },
      "COUNTRY" : {
        "value" : "AF"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "8"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "67432"
      }
    }
  }
}, {
  "row" : {
    "dimensionValues" : {
      "DATE" : {
        "value" : "20240820"
      },
      "APP" : {
        "value" : "ca-app-pub-4328354313035484~2152486667",
        "displayLabel" : "VPN - biubiuVPN Fast & Secure"
      },
      "COUNTRY" : {
        "value" : "AL"
      }
    },
    "metricValues" : {
      "CLICKS" : {
        "integerValue" : "0"
      },
      "ESTIMATED_EARNINGS" : {
        "microsValue" : "341"
      }
    }
  }
}, {
  "footer" : {
    "matchingRowCount" : "846"
  }
} ]

Documentation

Index

Constants

View Source
const (
	DefaultCurrencyCode = "USD"
	DefaultLanguageCode = "en-US"
)
View Source
const (
	FILTER_APP              = "APP"
	FILTER_COUNTRY          = "COUNTRY"
	FILTER_DATE             = "DATE"
	FILTER_PLATFORM         = "PLATFORM"
	FILTER_AD_UNIT          = "AD_UNIT"
	FILTER_FORMAT           = "FORMAT"
	FILTER_APP_VERSION_NAME = "APP_VERSION_NAME"
)

常用纬度

View Source
const (
	AD_REQUESTS        = "AD_REQUESTS"
	CLICKS             = "CLICKS"
	ESTIMATED_EARNINGS = "ESTIMATED_EARNINGS"
	IMPRESSIONS        = "IMPRESSIONS"
	IMPRESSION_CTR     = "IMPRESSION_CTR"
	IMPRESSION_RPM     = "IMPRESSION_RPM"
	MATCHED_REQUESTS   = "MATCHED_REQUESTS"
	MATCH_RATE         = "MATCH_RATE"
	SHOW_RATE          = "SHOW_RATE"
)

Variables

Functions

func DelClient

func DelClient(names ...string)

func Init

func Init(ctx context.Context, configs ...Config) (err error)

可以一次初始化多个实例或者 多次调用初始化多个实例

Types

type Config

type Config struct {
	Name       string `yaml:"Name" json:"name,optional"`
	AccountId  string `yaml:"AccountId" json:"accountId,optional"`
	AuthConfig gooauth.Config
}

type GoAdmob

type GoAdmob struct {
	Config         Config
	GoAuth         *gooauth.GoOAuth
	AdmobService   *admob.Service
	RequestTimeout int64 //default request timeout 30s
	// contains filtered or unexported fields
}

accessToken 会在60分钟后过期

func Default

func Default() *GoAdmob

func GetClient

func GetClient(names ...string) *GoAdmob

func New

func New(ctx context.Context, config Config) (*GoAdmob, error)

每次调用时都需要调用这个方法

func (*GoAdmob) AuthUrl

func (c *GoAdmob) AuthUrl() string

授权admobURL OAuth2.0

1、https://developers.google.com/admob/api/v1/getting-started?hl=zh-cn 创建一个新的授权客户端 获取client_id 和 client_secret

2、浏览器中执行 AuthUrl 方法获取授权code

3、获取code后执行 Exchange 方法获取token

func (*GoAdmob) Exchange

func (c *GoAdmob) Exchange(ctx context.Context, authorizationCode string) (*oauth2.Token, error)

获取token

func (*GoAdmob) GetAdUnits

func (c *GoAdmob) GetAdUnits() (*admob.ListAdUnitsResponse, error)

获取当前appId下所有的广告信息

func (*GoAdmob) GetApps

func (c *GoAdmob) GetApps() (*admob.ListAppsResponse, error)

获取账号下所有APP信息

func (*GoAdmob) GetReport

func (c *GoAdmob) GetReport(req *ReportReq) ([]*ResponseItem, error)

dimensions 指定查询维度,如:[]string{"DATE", "APP", "COUNTRY"}

SELECT DATE, APP, COUNTRY, CLICKS, ESTIMATED_EARNINGS FROM NETWORK_REPORT WHERE DATE >= '2021-09-01' AND DATE <= '2021-09-30'

AND COUNTRY IN ('US', 'CN')

GROUP BY DATE, APP, COUNTRY ORDER BY APP ASC, CLICKS DESC;

func (*GoAdmob) Refresh

func (o *GoAdmob) Refresh() error

RefreshToken and AdmobService admon token 有效期为60分钟,所有每次请求数据刷新下token

func (*GoAdmob) RefreshToken

func (c *GoAdmob) RefreshToken() error

刷新token

type ReportReq added in v1.2.109

type ReportReq struct {
	Dimensions      []string //查询维度列表
	AdUnits         []string //广告位
	Countries       []string //国家
	AdFormats       []string //原生、横幅、插屏、开屏、激励视频
	Platforms       []string //应用的移动操作系统平台(例如“Android”或“iOS”)。
	AppVersionNames []string //对于 Android,应用版本名称可以在 PackageInfo 中的 versionName 中找到。对于 iOS,可以在 CFBundleShortVersionString 中找到应用版本名称。警告:该维度与 ESTIMATED_EARNINGS 和 OBSERVED_ECPM 指标不兼容。
	MaxReportRows   int64    //最大返回数量
	Metrics         []string //查询字段、注意:这里的查询字段在不同的纬度下有互斥情况

	StartDate admob.Date
	EndDate   admob.Date

	CurrencyCode string //default currency USD
	LanguageCode string //default language en-US

	RetryWaitTime time.Duration
	RetryCount    int
}

type ResponseItem added in v1.2.110

type ResponseItem struct {
	Date            string
	AdUnit          string
	Country         string
	AdRequest       int64
	Clicks          int64
	Earnings        int64 //美分
	Impressions     int64
	ImpressionCtr   float64
	ImpressionRpm   int64 //美分
	MatchedRequests int64
	MatchRate       float64
	ShowRate        float64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL