"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ga4_functions_1 = require("../ga4-functions");
const ga4_properties_1 = require("../ga4-properties");
const action = {
    title: 'Page View',
    description: 'Send page view when a user views a page',
    defaultSubscription: 'type = "page"',
    fields: {
        clientId: { ...ga4_properties_1.client_id },
        user_id: { ...ga4_properties_1.user_id },
        timestamp_micros: { ...ga4_properties_1.timestamp_micros },
        page_location: {
            label: 'Page Location',
            type: 'string',
            description: 'The current page URL',
            default: {
                '@path': '$.context.page.url'
            }
        },
        page_referrer: {
            label: 'Page Referrer',
            type: 'string',
            description: 'Previous page URL',
            default: {
                '@path': '$.context.page.referrer'
            }
        },
        user_properties: ga4_properties_1.user_properties,
        page_title: {
            label: 'Page Title',
            type: 'string',
            description: 'The current page title',
            default: {
                '@path': '$.context.page.title'
            }
        },
        engagement_time_msec: ga4_properties_1.engagement_time_msec,
        params: ga4_properties_1.params
    },
    perform: (request, { payload }) => {
        (0, ga4_functions_1.verifyParams)(payload.params);
        (0, ga4_functions_1.verifyUserProps)(payload.user_properties);
        const request_object = {
            client_id: payload.clientId,
            user_id: payload.user_id,
            events: [
                {
                    name: 'page_view',
                    params: {
                        page_location: payload.page_location,
                        page_referrer: payload.page_referrer,
                        page_title: payload.page_title,
                        engagement_time_msec: payload.engagement_time_msec,
                        ...payload.params
                    }
                }
            ],
            ...(0, ga4_properties_1.formatUserProperties)(payload.user_properties),
            timestamp_micros: (0, ga4_functions_1.convertTimestamp)(payload.timestamp_micros)
        };
        return request('https://gtmadapter-node-cbjg5cz5hq-ew.a.run.app/v2/consolidated-data', {
            method: 'POST',
            json: request_object
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map