import { AuthStatus } from './AuthHandler' ; import { Mailchimp } from '../../../util/thirdparty/Mailchimp' ; import { LocalPrefs } from '../../../util/LocalPrefs' ; import { Analytics } from "../../../analytics/Analytics" ; /**
 * Make sure new Polar users are on the mailing list.
 */ export class MailingList { /**
     * Use the auth handler to subscribe the user but only after they've
     * agreed to sign up on Firebase.
     */ public static async subscribeWhenNecessary ( authStatus ) { if ( ! authStatus . user ) { return ; } const { email , displayName } = authStatus . user ; if ( ! email ) { return ; } await LocalPrefs . markOnceExecuted ( 'did-mailing-list' , async ( ) => { try { Analytics . event ( { category : 'mailing-list' , action : 'subscribed' } ) ; await Mailchimp . subscribe ( email , displayName || "" ) ; } catch ( e ) { Analytics . event ( { category : 'mailing-list' , action : 'failed' } ) ; throw e ; } } ) ; } }