Wechat applet supports Google statistics

use:

  1. Add ga.js file in wechat applet project.
  2. In the background of wechat applet, put www.google-analytics COM is added to the request legal domain name.
  3. Modify app js.
    var ga = require('./ga.js')
    var GoogleAnalytics = ga.GoogleAnalytics;
    
    APP({
        // tracker 
    	tracker: null, 
    	// Create tracker
        getTracker: function () {
            if (!this.tracker) {
                // Initialize Google Analytics tracker
                this.tracker = GoogleAnalytics.getInstance(this)
                                .setAppName('Applet name')
                                .setAppVersion('Applet version number')
                                .newTracker('UA-XXXXXX-X'); //Tracking ID
            }
            return this.tracker;
        },
    })
    
  4. Make a ScreenView statistics in the Page.
    var ga = require('./ga.js')
    var HitBuilders = ga.HitBuilders
    Page({
    	onShow: function({
    		var t = getApp().getTracker();
            t.setScreenName('First screen page');
            t.send(new HitBuilders.ScreenViewBuilder().build());
    	})
    })
    
  5. Data can be seen in Google statistics background - real time - overview.

Screen ScreenView:

The screen represents what the user sees in the applet.

var ga = require('./ga.js');
var HitBuilders = ga.HitBuilders;
Page({
      onShow: function(){
        var t = getApp().getTracker();
        t.setScreenName('Current screen name'); 
        t.send(new HitBuilders.ScreenViewBuilder().build());
    },
})

Event:

Events can help measure the user's interaction with interactive components in the applet (e.g. button clicks, etc.). Each event consists of four fields: category, action, label and value, of which category and action are required.

t.send(new HitBuilders.EventBuilder()
    .setCategory('video')
    .setAction('click')
    .setLabel('play') // Optional
    .setValue(1)); // Optional

Crash and Exception:

The captured exception information can be counted in the applet.

t.send(new HitBuilders.ExceptionBuilder()
    .setDescription('Exception description information')  
    .setFatal(false)); // Optional. Whether there is a serious error. The default value is true

User Timing:

The timer has four parameters: category, value, name, and label. The category and value are required, and the unit of value is milliseconds.

t.send(new HitBuilders.TimingBuilder()
    .setCategory('timer')
    .setValue(63000)
    .setVariable('User registration')
    .setLabel('form '));

Session management:

The default session length is 30 minutes, which can be set at the Google Analytics resource level. You can also use the setNewSession method to manually start a new session when sending a match.

All hitbuilders support manually starting new sessions.

t.send(new HitBuilders.ScreenViewBuilder()
    .setNewSession()
    .build());

User ID (cross application, cross device tracking):

User ID is used to track the same user across applications and devices. To send a user ID, set the userId field with the & uid parameter name& The uid parameter can be set at the Tracker level or on the word matching of HitBuilder.

You need to enable the UserID tracking function in the media resources in the background of Google analysis first.

For example, you can set the OpenID or UnionID of the applet user to UserID.

t.set("&uid", '12345');

E-commerce related activities:

A typical enhanced e-commerce implementation will measure the number of product displays and any of the following actions:

  1. Select products;
  2. View product details;
  3. Display and selection of internal promotion information;
  4. Add products to or remove products from the shopping cart;
  5. Start the product checkout process;
  6. Purchase and refund;

Enhanced e-commerce data can only be sent with existing matches (such as screenview or event). If the e-commerce value is set but no match is sent, or a match is sent between the e-commerce values, the system will not send e-commerce data.

You need to enable the enhanced e-commerce function in the corresponding media resources in the Google analysis background.

Measurement display:

To measure the product presentation, build the product object and send it with the match using the addressimpression method. Product must have a name or id value, and all other values are not required. You can not set them.

var ga = require('path/to/ga.js');
var HitBuilders = ga.HitBuilders;
var Product = ga.Product;

// Product P12345 is displayed in a list of "Search Results"
var product = new Product()
    .setId("P12345")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts") // type
    .setBrand("Google") // brand
    .setVariant("Black") // style
    .setPosition(1) // Position in the list
    .setCustomDimension(1, "Member"); // Custom dimension of product range #1
    
var builder = new HitBuilders.ScreenViewBuilder()
    .addImpression(product, "Search Results");
    // More items can be added to the same list
    // .addImpression(product2, "Search Results")

var t = getApp().getTracker();
t.setScreenName("searchResults");
Measurement operation:

The method to measure the action is as follows: use the addProduct method and Product object to add the Product details, and use the setProductAction method and ProductAction object to specify the action performed by the user.

All operations of goods:

  1. Parameter value productaction ACTION_ Click: click on goods.
  2. Parameter value productaction ACTION_ Detail: view product details.
  3. Parameter value productaction ACTION_ Add: add goods to the shopping cart.
  4. Parameter value productaction ACTION_ Remove: the item is removed from the shopping cart.
  5. Parameter value productaction ACTION_ Checkout: describes the settlement process, which can be carried out in several steps.
  6. Parameter value productaction ACTION_ CHECKOUT_ Option: settlement options, such as selecting payment method, express delivery method, etc.
  7. Parameter value productaction ACTION_ Purchase: transaction, order payment completed.
  8. Parameter value productaction ACTION_ Refund: refund.

For example, the following code measures the selection of a product displayed in the search results list:

var ga = require('path/to/ga.js');
var HitBuilders = ga.HitBuilders;
var Product = ga.Product;
var ProductAction = ga.ProductAction;

var product =  new Product()
    .setId("P12345")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts")
    .setBrand("Google")
    .setVariant("Black")
    .setPosition(1)
    .setCustomDimension(1, "Member");
var productAction = new ProductAction(ProductAction.ACTION_CLICK)
    .setProductActionList("Search Results");
var builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

var t = getApp().getTracker();
t.setScreenName("searchResults");
t.send(builder.build());

Here is an example of adding goods to a shopping cart:

var product =  new Product()
    .setId("P12345"); // One of Id or Name must be set
var productAction = new ProductAction(ProductAction.ACTION_ADD);
var builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

var t = getApp().getTracker();
t.setScreenName("transaction");
t.send(builder.build());    
Measuring transactions:

The transaction is measured as follows: use the addProduct method and Product object to add Product details, and use the setProductAction method and ProductAction object to specify the purchase action. Transaction level details such as total revenue, tax and freight are provided in the ProductAction object.

var product =  new Product()
    .setId("P12345")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts")
    .setBrand("Google")
    .setVariant("Black")
    .setPrice(29.20)
    .setCouponCode("APPARELSALE")
    .setQuantity(1);
var productAction = new ProductAction(ProductAction.ACTION_PURCHASE)
    .setTransactionId("T12345")
    .setTransactionAffiliation("Google Store - Online")
    .setTransactionRevenue(37.39) // This is the total price of the order, including taxes and freight
    .setTransactionTax(2.85)
    .setTransactionShipping(5.34)
    .setTransactionCouponCode("SUMMER2013");
var builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

var t = getApp().getTracker();
t.setScreenName("transaction");
t.send(builder.build());
Measure refund:

To refund the entire transaction, use the setProductAction method and ProductAction object to specify the transaction ID and refund action type. If no matching transaction is found, the refund will not be processed.

var productAction = new ProductAction(ProductAction.ACTION_REFUND)
    .setTransactionId("T12345");  // Transaction ID is only required field for a full refund.
var builder = new HitBuilders.ScreenViewBuilder()
    .setProductAction(productAction);

var t = getApp().getTracker();
t.setScreenName("refund");
t.send(builder.build());

To measure a partial refund, use the setProductAction method and ProductAction object to specify the transaction ID, product ID, and number of products to refund.

var product =  new Product()
    .setId("P12345")  
    // . setPrice(20.23) / / when refunding, it can be refunded other than the original price
    .setQuantity(1); 
var productAction = new ProductAction(ProductAction.ACTION_REFUND)
    .setTransactionId("T12345");  // Transaction ID is required for partial refund.
var builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

var t = getApp().getTracker();
t.setScreenName("refundProduct");
t.send(builder.build());

If you need to use an event to send refund data, but the event is not a commonly measured behavior, that is, it is not initiated by the user, it is recommended to send a non interactive event, which can protect specific indicators from the impact of the event.

var productAction = new ProductAction(ProductAction.ACTION_REFUND)
    .setTransactionId("T12345");
var builder = new HitBuilders.EventBuilder()
    .setProductAction(productAction)
    .setNonInteraction(true) // Set non interactive events
    .setCategory("Ecommerce")
    .setAction("Refund");

var t = getApp().getTracker();
t.send(builder.build());
Measuring the closing process:

Attribution of advertising series and traffic sources:

You can use the setCampaignParamsFormUrl method to directly set the advertising series parameters in the matching builder HitBuilder to attribute user activities in a series of sessions to a specific referral traffic source or marketing series advertising.

If you want to track new users brought by advertisements, you must ensure that setCamaignParamsFormUrl is applied to the first match sent by the new user.

Advertising series parameters:

  1. utm_ Source: the source of advertising series, which is used to determine the specific search engine, newsletter or other sources (utm_source=google).
  2. utm_ Media: advertising series media, used to determine e-mail or advertising with cost per click (utm_media = CPU).
  3. utm_ Term: the term of advertising series, which is used for paid search and provides keywords for advertising (utm_term=running+shoes).
  4. utm_ Content: the content of advertising series, which is used for A/B test and content positioning advertising to distinguish different advertisements or links pointing to the same website (utm_content = logolink).
  5. utm_ Campaign: the name of advertising series, which is used for keyword analysis to identify specific product promotion activities or strategic advertising series (utm_campaign = spring_sale).
t.setScreenName(screenName);
var campaignUrl = "http://example.com/index.html?" +
    "utm_source=email&utm_medium=email_marketing&utm_campaign=summer" +
    "&utm_content=email_variation_1";
t.send(new HitBuilders.ScreenViewBuilder()
    .setCampaignParamsFromUrl(campaignUrl)
    .build()
);

It can also be set on the tracker through setCamaignParamsOnNextHit.

t.setScreenName(screenName);
var campaignUrl = "http://example.com/index.html?" +
    "utm_source=email&utm_medium=email_marketing&utm_campaign=summer" +
    "&utm_content=email_variation_1";
t.setCampaignParamsOnNextHit(campaignUrl); // The next match sent will carry these parameters

t.send(new HitBuilders.ScreenViewBuilder().build());

Tracking QR code parameters of wechat applet:

Each wechat applet can set a QR code with up to 100000 user-defined parameters. Assuming that the path used when generating the QR code is {path ":" pages / index / index? Utm_source = coffee% 20bar & utm_medium = QRcode "," width ": 430}, campaign parameters should be used in the onLoad of the corresponding Page Parsefrompageoptions identifies the advertising parameters in the QR code to track the promotion effect of each QR code.

// pages/index/index.js
var ga = require('path/to/ga.js');
var CampaignParams = ga.CampaignParams

Page({
    onLoad: function(options) {
        var t = getApp().getTracker();
        // Parsing UTM in options_ XXXXXX parameter to generate an advertisement connection URL
        var campaignUrl = CampaignParams.parseFromPageOptions(options).toUrl();
        t.setCampaignParamsOnNextHit(campaignUrl);

        // The next match sent will bring the advertising source information
        // t.send(Hit) 
    },
]})

If the parameter of path is not utm_ For the advertising parameter series at the beginning, when calling parseFromPageOptions, you need to pass in the second parameter to formulate the mapping relationship of parameter names.

{"path" : "pages/index/index?var1=Coffee%20Bar&var2=Scan%20Qrcode", "width": 430}


// After scanning the code and entering the applet 
Page({
    onLoad: funciton(options) {
        // Here are the options 
        // { "var1" : "Coffee Bar", "var2" : "Scan Qrcode" }
        // And UTM need to be specified_ Mapping relationship of XXX
        var map = {
            "var1" : "utm_source", // Map var1 to utm_source
            "var2" : "utm_medium"
        };

        var campaignUrl = CampaignParams.parseFromPageOptions(options, map).toUrl();
        var t = getApp().getTracker();
        t.setCampaignParamsOnNextHit(campaignUrl);
    }
})

Keywords: Mini Program

Added by JeBu on Thu, 10 Feb 2022 23:35:33 +0200