import { loadGTAG } from "../google/loadGTAG.js";
import { MetricsGateway } from "./MetricsGateway.js";


export class GoogleAnalyticsMetrics extends MetricsGateway {
    constructor(key) {
        super();

        this.api = {
            gtag: loadGTAG(key)
        };

    }

    record(type, event) {
        const payload = Object.assign({}, event);

        if (typeof event.category === "string") {
            payload.event_category = event.category;
        }

        if (typeof event.label === "string") {
            payload.event_label = event.label;
        }

        this.api.gtag('event', type, payload);
    }
}
