import { AnalyticsBrowser } from '@segment/analytics-next';
export class SegmentTrackingProvider {
    constructor() {
        this.verbose = false;
    }
    initialize(props) {
        this.verbose = props.verbose;
        if (this.verbose) {
            // eslint-disable-next-line no-console
            console.log('SegmentProvider initialize');
        }
        const segmentKey = props.segmentKey;
        // We need to create an object here, as ts lint is unhappy otherwise
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        const integrations = props.segmentIntegrations;
        this.analytics = AnalyticsBrowser.load({
            writeKey: segmentKey,
            cdnURL: props.segmentCdn
        }, {
            integrations: Object.assign({}, integrations)
        });
    }
    identify(userID, userProperties = {}) {
        if (this.verbose) {
            // eslint-disable-next-line no-console
            console.log('SegmentProvider userID: ' + userID);
        }
        if (this.analytics) {
            this.analytics.identify(userID, userProperties);
        }
    }
    trackPageView(url) {
        if (this.verbose) {
            // eslint-disable-next-line no-console
            console.log('SegmentProvider url ', url);
        }
        if (this.analytics) {
            if (url) {
                this.analytics.page(url);
            }
            else {
                this.analytics.page(); // Uses window.url
            }
        }
    }
    trackSingleItem(item, properties) {
        if (this.verbose) {
            // eslint-disable-next-line no-console
            console.log('SegmentProvider: trackSingleItem ' + item, properties);
        }
        if (this.analytics) {
            this.analytics.track(item, { properties });
        }
    }
}
