0.1.40 • Published 8 months ago

analytics-sdk-generator v0.1.40

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
8 months ago

Analytics-SDK Generator

This project is a convenient for developers, data analysts and engineers alike.

It takes in a yaml file describing a mobile application and the analytics events that should be sent, and generates a corresponding type-checked SDK.

Try it out

yarn install
yarn ts-node src/bin/cli.ts transliterate \
  --input src/example/example-schema.yml \
  --output ./output \
  --implemenmtation ./src/example/example-implementation
yarn ts-node src/example/example-client.ts

The transliterate command parses your analytics schema in ./src/example/example-schema.yml, generates the code, and writes it to ./output. Specifying --implementation is meant to specify a file whose default export is your analytics reporter implementation; by default, itonly does console.log(...)

Schema format

The format was designed to expose as much json-schema as possible, while reducing verbosity. Any event property, trait, or shared definition is intended to be full json-schema 2019-09, but implementation is incomplete.

The file is divided in 4 sections.

Header

application:
  name: My Application
  version: 1.2.3

$defs

JSON-Schema 2019-09 changed definitions to $defs. Any type defined here can be reused throughout the schema file using the usual $ref: "#/$defs/YourThing"

$defs:
  AnotherThing:
    type: string
    format: uuid

  YourThing:
    type: object
    properties:
      key1:
        type: string
      key2:
        $ref: "#/$defs/AnotherThing"

Traits

Traits are key values set on a per-user basis, not on events.

traits:
  user_type:
    type: string
    enum:
    - manager
    - owner
    - end_user
  users_thing:
    $ref: "#/$defs/YourThing"

Screens

Screens (and Tracks) are the two main event types, and as such are first class citizens.

screens:
  Welcome:
    name: welcome screen
    features:
    - Onboarding
    description: |
      This screen is the first screens users see when using the app.
    properties:
      is_first_open:
        description: Wether this is the first time the user opens the app
        type: boolean
      another_property:
        type: boolean
    required:
      - another_property
    tracks:
    - SomeTrack
    links:
    - AnotherScreen

Welcome is the event key. It will be used as the function names, and should be a valid javascript variable name.

name: welcome is the event name. The default is to re-use the event key.

features is a list of features this event is associated with.

description allows you to describe this event in free text. It will be included as a comment in the code, potentially displayed by your IDEs auto-suggestion.

properties are the properties this event is expected to have. All properties are expressed in json-schema form.

required is the list of property names that must be present in the event. It defaults to empty. Any property listed will be non-optional in the property types generated.

tracks is a list of track type events associated to this screen. Each event listed here will also result in an additional function in the screen function files.

links is a list of screen type events associated with this screen, typically screens a user can navigate to from here.

Tracks

Tracks are events that can be emitted based on user interactions with your app that are not navigation based. The format is identical, except there are no links.

tracks:
  SomeTrack:
    features:
    - Onboarding
    description: |
      This event is emitted when something happens
    properties:
      some_property:
        description: Wether this is the first time the user opens the app
        type: boolean

Using the code

Look at ./src/examples/example-client.ts.

All screen events will result in a file in ./$outputDirectory/screens/$EventKey.ts. The default export will be the analytics function that emits that screen event.

All track events associated with this screen will also be included in this file, exported by name.

import screen, * as tracks from './$outputDirectory/screens/Welcome'

//  emit type: screen, name: welcome screen, {is_first_open,another_property}
screen({is_first_open: true, another_property: "some string"})

//  emit type: track, name: SomeTrack, {some_property}
tracks.SomeTrack({some_property: "another property"})
0.1.9-ac1ed8a6

8 months ago

0.1.12-0f85c4cb

8 months ago

0.1.21-f1c20c85

8 months ago

0.1.15-f1c20c85

8 months ago

0.1.14-f38d5beb

8 months ago

0.1.7-6481ea34

8 months ago

0.1.10-f92cdf91

8 months ago

0.1.8-8a0e80d0

8 months ago

0.1.16-f1c20c85

8 months ago

0.1.19-f1c20c85

8 months ago

0.1.18-f1c20c85

8 months ago

0.1.2-071f7f0f

8 months ago

0.1.3-85a430e2

8 months ago

0.1.13-b78f81c7

8 months ago

0.1.20-f1c20c85

8 months ago

0.1.4-8257179f

8 months ago

0.1.17-f1c20c85

8 months ago

0.1.11-91b7a086

8 months ago

0.1.6-4359265c

8 months ago

0.1.5-cd473451

8 months ago

0.1.1-112c1db7

2 years ago

0.1.41-5b754c54

3 years ago

0.1.42-2700c67a

3 years ago

0.1.30

3 years ago

0.1.38-710c38cc

3 years ago

0.1.35-aef656fc

3 years ago

0.1.40-1ef3e77d

3 years ago

0.1.34-e032d97e

3 years ago

0.1.36-a984ca98

3 years ago

0.1.30-5198b4a0

3 years ago

0.1.32-7381b918

3 years ago

0.0.1-test

3 years ago

0.1.31-cb08e10e

3 years ago

0.1.33-92ec9000

3 years ago

0.1.40

3 years ago

0.1.39-afcad994

3 years ago

0.1.38

3 years ago

0.1.26-d8ef148c

3 years ago

0.1.23-ae7eab66

3 years ago

0.1.29-4b7ea9e8

3 years ago

0.1.22-2e243935

3 years ago

0.1.29

3 years ago

0.1.28-f284c905

3 years ago

0.1.27-c7a6afc6

3 years ago

0.1.20-72e6c9ce

3 years ago

0.1.24-70b0f2ea

3 years ago

0.1.25-3633cf53

3 years ago

0.1.21-dc3d03a5

3 years ago

0.1.19-b30ed967

3 years ago

0.1.18-fc7dfa11

3 years ago

0.1.17-7cbfd7d6

3 years ago

0.1.16

3 years ago

0.1.16-53f8867c

3 years ago

0.1.15-592bfb7b

3 years ago

0.1.14

3 years ago

0.1.14-55b0dcfa

3 years ago

0.1.13

3 years ago

0.1.13-c83849f6

3 years ago

0.1.12

3 years ago

0.1.12-af56e624

3 years ago

0.1.11

3 years ago

0.1.11-f39149a0

3 years ago