@userdive/agent
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

@userdive/agent

npm version Build Status styled with prettier

Build Status

Official USERDIVE module for webpage analytics

Table of Contents

Install

npm install @userdive/agent --save

Usage

Basic Usage

import Agent from "@userdive/agent";

const agent = new Agent("projectId", "auto");
agent.send("pageview");

Custom Dimensions

docs

import Agent from "@userdive/agent";

const agent = new Agent("projectId", "auto");
agent.send("pageview", {
    dimension15: "My Custom Dimension"
});
agent.set({
    dimension15: "My Custom Dimension"
});

agent.set("dimension15", "My Custom Dimension");

Send Event

import Agent from "@userdive/agent";

const agent = new Agent("projectId", "auto");
agent.send("pageview");
agent.send("event", {
    eventCategory: "EC",
    eventAction: "Cart",
    eventLabel: "add",
    eventValue: 2000
});

Register Plugin ( in plugin code )

class MyPlugin {
    constructor(agent, opts) {
        this.opts = opts || { msg: "hi" };
    }

    greeting(target) {
        const name = target || "user";
        console.log(this.opts.msg + ", " + name);
    }
}

Use Plugin

import Agent from "@userdive/agent";
import Myplugin from "path/to/plugin";

const agent = new Agent("projectId", "auto");
agent.provide("myplugin", MyPlugin);
agent.require("myplugin", { msg: "hello" }); // provided name
agent.run("myplugin", "greeting", "everyone");
// => output 'hello, everyone'

Contribute

PRs accepted. join us

License

GPLv3. Full license text is available in LICENSE

Readme

Keywords

Package Sidebar

Install

npm i @userdive/agent

Weekly Downloads

4

Version

3.0.0

License

GPL-3.0

Unpacked Size

104 kB

Total Files

51

Last publish

Collaborators

  • userdive