• Retrieves and validates stored UTM parameters for a specific service.

    This function reads a serialized UTM object from sessionStorage under the key defined by UTM_STORAGE_KEY. It ensures that:

    • The stored object exists and is valid JSON.
    • The UTM data has not expired (based on its expiry timestamp).
    • The stored landing page corresponds to the provided service
    • which basically means the utm should be related to the service which this mapping is declared in URL_TO_UTM_SERVICE_MAP or it returns null.

    If any of these checks fail, the function clears the stored data and returns null.

    Parameters

    • service: UTM_SERVICES_ENUM

      The service identifier to validate the stored UTM data against.

    Returns Record<string, any> | null

    The parsed UTM parameters object if valid, or null if expired, mismatched, or invalid.

    import getUTMParams from '@/utils/getUTMParams';
    import { UTM_SERVICES_ENUM } from '@/constants/utm';

    const utm = getUTMParams(UTM_SERVICES_ENUM.INSURANCE_BODY);
    if (utm) {
    console.log('Valid UTM parameters related to insurance body service:', utm);
    } else {
    console.log('No valid UTM data found.');
    }