Swift uses the alliance to implement the statistical analysis course of application

Source: Internet
Author: User
Tags uikit

1, what is the Friendship Union (umeng.com)

(1) The Union is committed to providing mobile developers with professional data analysis, development and operation components and extension services. Services include mobile application statistical analysis and segmentation industry mobile game statistical analysis, social sharing components, message push, Automatic Updates, user feedback, error analysis and other products.
(2) The Alliance offers multi-platform services such as iOS, Android, and Windows Phone.
2, the application of the League of Friends statistical analysis

The Friendship Alliance statistical Analysis Platform is the largest mobile application statistical analysis platform in China. Used to help mobile application developers to statistic and analyze traffic sources, content usage, user attributes, and behavioral data, so that developers can use data to make decisions about product, operation, and promotion strategies.

3, using the sample
As the code sample provided by the official website is objective-c, I will show you how to use Swift to tune the AU's SDK.
(1) Access to Appkey

Before you integrate the AU SDK, you need to register with the league website and add new apps to get Appkey

(2) Download Statistical SDK

Download statistics SDK Analytics-ios-sdk.zip and unzip

(3) Add the SDK to the project

Drag the libmobclicklibrary.a and MobClick.h two files in the SDK into the Xcode engineering directory structure.


Also remember to add a bridging file in which to add a reference to the ally analysis.


#import "MobClick.h"

(4) Add the configuration in the Appdelegate.swift, the code is as follows:

The configuration mainly includes filling in the Appkey, setting the sending strategy and filling in the channel ID three part

1,ios platform Data delivery strategy includes batch (send at startup) and Send_interval (send at intervals) two, the Union by default use to send at startup (more provincial traffic), you can change the sending policy in code Reportpolicy:batch.

2, channels can be defined freely. When viewing data, the channel is a dimension that is subdivided as a data. When Channelid is nil or "", the default is treated as the "App Store" channel.

3, because IOS9 introduced the app Transport Security (ATS) feature and asked the app to access the network using the HTTPS protocol, developers are required to add settings in the project so that HTTP requests can be sent. See also my other article: Swift-Web request app transport security has blocked a cleartext wrong

Import Uikit

@UIApplicationMain
Class Appdelegate:uiresponder, Uiapplicationdelegate {

var Window:uiwindow?

Func Application (Application:uiapplication,
Didfinishlaunchingwithoptions launchoptions: [Nsobject:anyobject]? -> Bool {

Mobclick.startwithappkey ("564d3bf567e58e8179000811", Reportpolicy:batch,
Channelid: "hangge.com")

return True
}

Func applicationwillresignactive (application:uiapplication) {
}

Func Applicationdidenterbackground (application:uiapplication) {
}

Func Applicationwillenterforeground (application:uiapplication) {
}

Func applicationdidbecomeactive (application:uiapplication) {
}

Func applicationwillterminate (application:uiapplication) {
}
}

(5) Test effect
The above configuration after the direct start test (true machine simulator can), into the league backstage, you can see the new user information.


4, add the statistics of specific pages
Only the page statistics are integrated correctly to get the correct page access path, access depth (PV) data. To implement a page's statistics, you need to match the corresponding page count method in each view.
For example, to count the "about" page, add the following method on the About page (Aboutmeviewcontroller.swift)

Import Uikit

Class Aboutmeviewcontroller:uiviewcontroller {

Override Func Viewdidload () {
Super.viewdidload ()
}

Override func Viewwillappear (Animated:bool) {
Super.viewwillappear (animated)
Mobclick.beginlogpageview ("homepage")
}

Override func Viewwilldisappear (Animated:bool) {
Super.viewwilldisappear (animated)
Mobclick.endlogpageview ("homepage")
}

Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}

5, use, statistics custom events
Custom events are divided into count events and calculated events. Here is an example of a count event, such as a "buy" button on our page, and I want the user to click the button once to record it.
(1) First select "Count event" when adding an event in the league background.

(2) The program code is as follows:

@IBAction func Purchaseclick (sender:anyobject) {
Record the "Buy" button hits, while assuming that 4 books have been purchased
Let dict = ["Type": "Book", "Quantity": "4"]
Mobclick.event ("Purchase", Attributes:dict)
}

(3) The following statistical data can be seen in the backstage of the League of Friends:

Related Article
Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.