npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mp-ga-tracker

v1.1.1

Published

GA tracking SDK for WeChat Miniprogram.

Downloads

3

Readme

mp-ga-tracker

GA tracking SDK for WeChat Miniprogram.

Installation

$ npm install mp-ga-tracker --save

Initialization

import GaTracker, { DS_WEB, DS_APP } from 'mp-ga-tracker'

const config = {
  server: {
    host: '<ga_proxy_server_host_url>',
    // ?optional, default -> '/collect'
    singleHitEndpoint: '<ga_single_hit_collect_endpoint>',
    // ?optional, default -> '/batch'
    batchHitEndpoint: '<ga_multiple_hits_collect_endpoint>',
    // ?optional, default -> `POST`
    method: 'POST',
  },
  // set the default fallback value to the dh
  defaultDh: 'default.document_host_name.com',
  // set the params that would be sent for every single hit
  generalParams: {
    tid: '<ga_tracking_id>',
    // ?optional, protocol version, default -> 1
    v: 1,
    // ?optional, data source, enum value would be either DS_WEB or DS_APP, default -> DS_WEB
    ds: DS_WEB,
    // required when the ds setting above is DS_APP, otherwise the value won'be used
    an: '<application_name>',
    // ?optional, application id
    aid: '<application_id>',
    // ?optional, application version
    av: '<application_version>',
  },
  // ?optional, for the hit console logging, default -> false
  logging: false,
}

const gaTracker = new GaTracker(config)

Usage

/* SETTING UP */

// Setting the client ID, which normally would be WeChat user's openId
// Note that the cid should be set up ASAP once the gaTracker has been initialized
// The ga hit would be pushed into the internal queue and wouldn't be sent to the server before the cid has been set
gaTracker.setCid('the_client_id')

// Setting the campaign params
// All of these params are optional and could be set at any time
// Every single hit in the internal queue that haven't been sent out would be affected when the campaign params updates
gaTracker.setCampaignParams({
  cn: 'campaign_name',
  cs: 'campaign_source',
  cm: 'campaign_medium',
  ck: 'campaign_keyword',
  cc: 'campaign_content',
})



/* TRACKING */

// Tracking screenview, either string or object is ok to be used
gaTracker.trackScreenview('screen_name', ...enhancers)
gaTracker.trackScreenview({
  // required
  cd: 'sceen_name',
  // ?optional, default -> 0
  ni: 1,
}, ...enhancers)

// Tracking pageview
gaTracker.trackPageview({
  // required, document_title
  dt: 'document_title',
  // opitonal if the defaultDh has been set up when the gaTracker is initialized
  dh: 'document_host_name',
  // ?optional, document_path, default -> the MP current page path
  dp: 'dopcument_path',
  // ?optional, default -> 0
  ni: 1,
}, ...enhancers)
// trackPageview supports string argument as well, it would be treated as the dt value
// Note that it won't work if the defaultDh hasn't been setup
gaTracker.trackPageview('document_title', ...enhancers)

// Tracking event
// Besides the event info, extra screenview / pageview info would be attached as well based on the ds (data_source) value:
// when the ds is DS_WEB, the last pageview info would be attached
// when the ds is DS_APP, the last screenview info would be attached
gaTracker.trackEvent({
  // required
  ec: 'event_category',
  // reuqired
  ea: 'event_action',
  // ?optional
  el: 'event_label',
  // ?optional
  ev: 'event_value',
  // ?optional, default -> 0
  ni: 1,
}, ...enhancers)

List of enhancement plugins

  • mp-ga-enhancer-ecommerce
$ npm install mp-ga-enhancer-ecommerce --save