gAnalytics

立即使用

概述

Google Analytics是著名互联网公司Google为提供的数据统计服务。可以对目标网站、移动端App进行访问数据统计和分析,并提供多种参数供网站、App拥有者使用。如今对于移动应用的市场分析正存在着巨大的缺口,需求显而易见。虽然目前市面上不乏这样的分析服务,但是能够真正追踪所有相关数据的应用还没有出现。而谷歌旗下知名产品Google Analytics(谷歌分析)适时发布了新的移动应用分析服务(Google Analytics App),旨在填补这一空白的同时帮助营销人员以及开发者更好地衡量他们的应用程序。详情参考 谷歌分析文档

本模块封装了 Google Analytics 移动端统计分析的功能。开发者只要在 Google 开放平台注册账号,创建自己的项目,获取对应的追踪文件,即可集成本模块到自己的 App。轻松实现应用统计分析功能。

模块使用攻略

1,账号申请

使用本模块之前需先到谷歌开放平台申请注册 开发者账号 并登陆。

申请注册 申请注册

2,创建应用

申请谷歌开发者账号后点击注册邮箱里的激活链接,激活开发者账号。当你成功注册 Google 开发者账号后就可以在此账号里创建谷歌分析的应用了。

申请注册

点击 start 开始创建。

申请注册

点击 sign 开始注册。

申请注册

进入创建页面,填写相应信息,点击 next。

申请注册

选择 Apps。

申请注册

输入相关信息,点击 create。

申请注册

选择同意。

申请注册

接下来选择不同的平台以创建配置文件。

申请注册

输入包名(bundle id)等相关信息(iOS端)。

申请注册

点击下一步等待若干分钟(iOS端)。

申请注册

创建配置文件(GoogleService-Info)完成,点击下载(iOS端)。

申请注册

3,自定义附加模块(iOS端)

接下来下载 gAnalyticsAppendix 模块 zip 包并解压,把 zip 包内的 GoogleService-Info.plist 文件替换为自己上一步创建下载的 .plist 文件。然后重新压缩为 zip 包文件上传自定义模块,云编译时勾选该模块。

模块接口

setUserID

Sets the user ID property. This feature must be used in accordance with Google's Privacy Policy.

setUserID({params})

params

userID:

  • 类型:字符串
  • 描述:The user ID to ascribe to the user of this app on this device, which must be non-empty and no more than 256 characters long. 不传表示 removes the user ID.

示例代码

var ga= api.require('gAnalytics');
ga.setUserID({userID:'****'});

  

可用性

iOS 系统,Android 系统

可提供的 1.0.0 及更高版本

setScreenName

设置当前屏幕显示页面。The screen name and screen class remain in effect until a new call to setScreenName is made.

setScreenName({params})

params

screenName:

  • 类型:字符串
  • 描述:(可选项)The name of the current screen. Should contain 1 to 100 characters.不传表示 clear the current screen name.

classOverride:

  • 类型:字符串
  • 描述:The name of the screen class. Should contain 1 to 100 characters.

示例代码

var ga= api.require('gAnalytics');
ga.setScreenName({
    classOverride:'indexHtml'
    screenName:'首页'
});

  

可用性

iOS 系统,Android 系统

可提供的 1.0.0 及更高版本

setUserPropertyString

Sets a user property to a given value. Up to 25 user property names are supported. Once set, user property values persist throughout the app lifecycle and across sessions.

The following user property names are reserved and cannot be used: first_open_time、last_deep_link_referrer、user_id

setUserPropertyString({params})

params

property:

  • 类型:字符串
  • 描述:(可选项)The value of the user property. Values can be up to 36 characters long.不传表示 removes the user property.

name:

  • 类型:字符串
  • 描述:The name of the user property to set. Should contain 1 to 24 alphanumeric characters or underscores and must start with an alphabetic character. The "firebase", "google", and "ga_" prefixes are reserved and should not be used for user property names.

示例代码

var ga = api.require('gAnalytics');
ga.setUserPropertyString({
    property: 'food',
    name: 'favorite_food'
});

  

可用性

iOS 系统,Android 系统

可提供的 1.0.0 及更高版本

logEventWithName

Logs an app event. The event can have up to 25 parameters. Events with the same name must have the same parameters. Up to 500 event names are supported. Using predefined events and/or parameters is recommended for optimal reporting.

The following event names are reserved and cannot be used: ad_activeview、ad_click、ad_exposure、ad_impression、ad_query、adunit_exposure、app_clear_data、app_remove、app_update、error、first_open、in_app_purchase、notification_dismiss、notification_foreground、notification_open、notification_receive、os_update、screen_view、session_start、user_engagement

logEventWithName({params})

params

logEvent:

  • 类型:字符串
  • 描述:(可选项)The name of the event. Should contain 1 to 40 alphanumeric characters or underscores.The name must start with an alphabetic character. Some event names are reserved. See FIREventNames for the list of reserved event names. The "firebase", "google", and "ga_" prefixes are reserved and should not be used. Note that event names are case-sensitive and that logging two events whose names differ only in case will result in two distinct events.
  • 默认:select_content

parameters:

  • 类型:JSON 对象
  • 描述:(可选项)The JSON of event parameters. 不传表示 that the event has no parameters.Parameter names can be up to 40 characters long and must start with an alphabetic character and contain only alphanumeric characters and underscores.Only String Number (signed 64-bit integer and 64-bit floating-point number) parameter types are supported. NSString parameter values can be up to 100 characters long. The "firebase", "google", and "ga_" prefixes are reserved and should not be used for parameter names.
  • 内部字段:参考 parameters

示例代码

var ga = api.require('gAnalytics');
ga.logEventWithName({
    logEvent: 'select_content',
    parameters: {
       item_id:'p7654',
       item_name:'abc',
       content_type:'image'
    }
});

  

可用性

iOS 系统,Android 系统

可提供的 1.0.0 及更高版本

FIREventNames

  • 类型:字符串
  • 描述:FIREventNames
  • 取值范围:
    • add_payment_info:Add Payment Info event. This event signifies that a user has submitted their payment information to your app.
    • add_to_cart: E-Commerce Add To Cart event. This event signifies that an item was added to a cart for purchase. Add this event to a funnel with kFIREventEcommercePurchase to gauge the effectiveness of your checkout process.
    • add_to_wishlist: E-Commerce Add To Wishlist event. This event signifies that an item was added to a wishlist. Use this event to identify popular gift items in your app.
    • app_open: App Open event. By logging this event when an App becomes active, developers can understand how often users leave and return during the course of a Session. Although Sessions are automatically reported, this event can provide further clarification around the continuous engagement of app-users.
    • begin_checkout: E-Commerce Begin Checkout event. This event signifies that a user has begun the process of checking out. Add this event to a funnel with your kFIREventEcommercePurchase event to gauge the effectiveness of your checkout process.
    • campaign_details: Campaign Detail event. Log this event to supply the referral details of a re-engagement campaign.
    • checkout_progress: Checkout progress.
    • earn_virtual_currency: Earn Virtual Currency event. This event tracks the awarding of virtual currency in your app.
    • ecommerce_purchase: E-Commerce Purchase event. This event signifies that an item was purchased by a user. Note: This is different from the in-app purchase event, which is reported automatically for App Store-based apps.
    • generate_lead: Generate Lead event. Log this event when a lead has been generated in the app to understand the efficacy of your install and re-engagement campaigns.
    • join_group: Join Group event. Log this event when a user joins a group such as a guild, team or family. Use this event to analyze how popular certain groups or social features are in your app.
    • level_up: Level Up event. This event signifies that a player has leveled up in your gaming app. It can help you gauge the level distribution of your userbase and help you identify certain levels that are difficult to pass.
    • login: Login event. Apps with a login feature can report this event to signify that a user has logged in.
    • post_score: Post Score event. Log this event when the user posts a score in your gaming app. This event can help you understand how users are actually performing in your game and it can help you correlate high scores with certain audiences or behaviors.
    • present_offer: Present Offer event. This event signifies that the app has presented a purchase offer to a user. Add this event to a funnel with the kFIREventAddToCart and kFIREventEcommercePurchase to gauge your conversion process.
    • purchase_refund: E-Commerce Purchase Refund event. This event signifies that an item purchase was refunded.
    • remove_from_cart: Remove from cart event.
    • search: Search event. Apps that support search features can use this event to contextualize search operations by supplying the appropriate, corresponding parameters. This event can help you identify the most popular content in your app.
    • select_content: Select Content event. This general purpose event signifies that a user has selected some content of a certain type in an app. The content can be any object in your app. This event can help you identify popular content and categories of content in your app.
    • set_checkout_option: Set checkout option.
    • share: Share event. Apps with social features can log the Share event to identify the most viral content.
    • sign_up: Sign Up event. This event indicates that a user has signed up for an account in your app. The parameter signifies the method by which the user signed up. Use this event to understand the different behaviors between logged in and logged out users.
    • spend_virtual_currency: Spend Virtual Currency event. This event tracks the sale of virtual goods in your app and can help you identify which virtual goods are the most popular objects of purchase.
    • tutorial_begin: Tutorial Begin event. This event signifies the start of the on-boarding process in your app.
    • tutorial_complete: Tutorial End event. Use this event to signify the user's completion of your app's on-boarding process.
    • unlock_achievement: Unlock Achievement event. Log this event when the user has unlocked an achievement in your game. Since achievements generally represent the breadth of a gaming experience, this event can help you understand how many users are experiencing all that your game has to offer.
    • view_item: View Item event. This event signifies that some content was shown to the user. This content may be a product, a webpage or just a simple image or text. Use the appropriate parameters to contextualize the event. Use this event to discover the most popular items viewed in your app.
    • view_item_list: View Item List event. Log this event when the user has been presented with a list of items of a certain category.
    • view_search_results: View Search Results event. Log this event when the user has been presented with the results of a search.
    • level_start: Level Start event. Log this event when the user starts a new level.
    • level_end: Level End event. Log this event when the user finishes a level.

parameters

  • 类型:字符串
  • 描述:FIREventNames
  • 内部字段:
    • achievement_id:Game achievement ID(String)
    • aclid: Ad Network Click ID (String). Used for network-specific click IDs which vary in format.
    • affiliation: The store or affiliation from which this transaction occurred (String).
    • campaign: The individual campaign name, slogan, promo code, etc. Some networks have pre-defined macro to capture campaign information, otherwise can be populated by developer. Highly Recommended (String).
    • character:Character used in game (String).
    • checkout_step: The checkout step (1..N) (unsigned 64-bit integer as Number).
    • checkout_option: Some option on a step in an ecommerce flow (String).
    • content: Campaign content (String).
    • content_type: Type of content selected (String).
    • coupon: Coupon code for a purchasable item (String).
    • cp1: Campaign custom parameter (String). Used as a method of capturing custom data in a campaign. Use varies by network.
    • creative_name: The name of a creative used in a promotional spot (String).
    • creative_slot: The name of a creative slot (String).
    • currency: Purchase currency in 3-letter format (String).
    • destination: Flight or Travel destination (String).
    • end_date: The arrival date, check-out date or rental end date for the item. This should be in YYYY-MM-DD format (String).
    • flight_number: Flight number for travel events (String).
    • group_id: Group/clan/guild ID (String).
    • index: Index of an item in a list (signed 64-bit integer as Number).
    • item_brand: Item brand (String).
    • item_category: Item category (String).
    • item_id:Item ID (String).
    • item_location_id: The Google Place ID (String) that corresponds to the associated item. Alternatively, you can supply your own custom Location ID.
    • item_name: Item name (String).
    • item_list: The list in which the item was presented to the user (String).
    • item_variant: Item variant (String).
    • level: Level in game (signed 64-bit integer as Number).
    • location: Location (String). The Google Place ID that corresponds to the associated event. Alternatively, you can supply your own custom Location ID.
    • medium: The advertising or marketing medium, for example: cpc, banner, email, push. Highly recommended (String).
    • number_of_nights: Number of nights staying at hotel (signed 64-bit integer as Number).
    • number_of_passengers: Number of passengers traveling (signed 64-bit integer as Number).
    • number_of_rooms: Number of rooms for travel events (signed 64-bit integer as Number).
    • origin: Flight or Travel origin (String).
    • price: Purchase price (double as Number).
    • quantity: Purchase quantity (signed 64-bit integer as Number).
    • score: Score in game (signed 64-bit integer as Number).
    • search_term: The search string/keywords used (String).
    • shipping: Shipping cost (double as Number).
    • sign_up_method: Sign up method (String).
    • method: A particular approach used in an operation; for example, "facebook" or "email" in the context of a sign_up or login event. (String).
    • source: The origin of your traffic, such as an Ad network (for example, google) or partner (urban airship). Identify the advertiser, site, publication, etc. that is sending traffic to your property. Highly recommended (String).
    • start_date: The departure date, check-in date or rental start date for the item. This should be in YYYY-MM-DD format (String).
    • tax:Tax amount (double as Number).
    • term: If you're manually tagging keyword campaigns, you should use utm_term to specify the keyword (String).
    • transaction_id:A single ID for a ecommerce group transaction (String).
    • travel_class: Travel class (String). - value: A context-specific numeric value which is accumulated automatically for each event type. This is a general purpose parameter that is useful for accumulating a key metric that pertains to an event. Examples include revenue, distance, time and points. Value should be specified as signed 64-bit integer or double as Number.
    • virtual_currency_name: Name of virtual currency type (String).
    • level_name: The name of a level in a game (String).
    • success: The result of an operation. Specify 1 to indicate success and 0 to indicate failure (unsigned integer as Number).
    • extend_session:Indicates that the associated event should either extend the current session or start a new session if no session was active when the event was logged. Specify YES to extend the current session or to start a new session; any other value will not extend or start a session.