Coder Social home page Coder Social logo

mntm-lib / stats Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 48 KB

A package for integrating analytics tools.

Home Page: https://npm.im/@mntm/stats

TypeScript 100.00%
vk vkcom vkontakte gtm google-tag-manager amplitude fb facebook pixel stats statistics analytics

stats's Introduction

@mntm/stats GitHub license npm bundle size

Inspired by vk-stat

A package for integrating analytics tools.

Implemented providers

Implemented pixels

Prepare

[GTM] Google Tag Manager

When using Universal Analytics with GTM, need set storage:none. Without these settings will not work GA, when you install GTM in iframe.

[VK] VK Statistics

You need request permissions for statEvents.addMiniApps in miniapps with mini_app_id.

Installation

We recommend to use yarn for dependency management:

yarn add @mntm/stats

Event params

{
  // [GTM|GA|UA|VK] event category
  category: string;

  // [GTM|GA|UA] event label
  label: string;

  // [VK|GA|UA|YM] screen where event occurred
  screen: string;

  // [VK|AMP] additional parameters
  params: Record<string, unknown>;
}

Usage

import {
  prepareParams,
  createProviderGTM,
  createSend
} from '@mntm/stats';

// Re-assigns all query params, for example, for UTM tags.
prepareParams();

// Create send function
const sendStats = createSend([
  createProviderGTM('GTM-XXXXXXX')
]);

// Send event to all providers
sendStats('launch', {
  label: 'web_app'
});

VK API implementation

Need for VK Statistics provider:

// See @mntm/painless-bridge for enhanced bridge implementation
import bridge from '@vkontakte/vk-bridge';

// Early token initialization
const token = bridge.send('VKWebAppGetAuthToken', {
  // Your app_id
  app_id: 7415273,
  scope: ''
});

// Example of reuseable implementation
const api = async (method: string, params: Record<string, unknown>) => {
  const { access_token } = await token;

  const result = await bridge.send('VKWebAppCallAPIMethod', {
    method,
    params: Object.assign({
      access_token,
      v: '5.160'
    }, params);
  });

  return result;
};

Contributing

Development of @mntm/stats happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements.

License

@mntm/stats is MIT licensed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.