diff --git a/apps/research/src/components/article/article-payments/ProCheckoutCard.tsx b/apps/research/src/components/article/article-payments/ProCheckoutCard.tsx index 32941a96..76ee48af 100644 --- a/apps/research/src/components/article/article-payments/ProCheckoutCard.tsx +++ b/apps/research/src/components/article/article-payments/ProCheckoutCard.tsx @@ -16,7 +16,7 @@ const { Title, Text } = Typography; const { useToken } = theme; const features = [ - 'The weekly market report keeping you up to speed', + 'Ahead of the Curve – The Weekly Market Report', 'The monthly outlook helping you plan ahead', 'Token assessments based on data and economic theory', 'Industry insights from our in-depth reports', diff --git a/apps/research/src/services/subscription.ts b/apps/research/src/services/subscription.ts index ea1d6542..532fa411 100644 --- a/apps/research/src/services/subscription.ts +++ b/apps/research/src/services/subscription.ts @@ -16,6 +16,19 @@ export const researchApi = createApi({ baseQuery: fetchBaseQuery({ baseUrl: `https://${process.env.NEXT_PUBLIC_API_DOMAIN}`, prepareHeaders: async (headers) => { + //@ts-ignore + window.gtag( + 'get', + process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID!, + 'client_id', + (clientId: string) => { + // TODO: check if localstorage says cookie-product yes + const check = localStorage.getItem('cookies-product'); + if (check === 'YES') { + headers.set('x-client-id', `${clientId}`); + } + } + ); const token = await getIdToken(); headers.set('Content-Type', 'application/json'); if (token) { diff --git a/packages/core/index.ts b/packages/core/index.ts index 4c3850a0..68635699 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -198,6 +198,8 @@ export const acceptCookie = () => { //@ts-ignore localStorage.setItem('showCookies', 'NO'); //@ts-ignore + localStorage.setItem('cookies-product', 'YES'); + //@ts-ignore window.gtag('consent', 'update', { ad_storage: 'denied', analytics_storage: 'granted', @@ -207,6 +209,8 @@ export const acceptCookie = () => { export const denyCookie = () => { //@ts-ignore localStorage.setItem('showCookies', 'NO'); + //@ts-ignore + localStorage.setItem('cookies-product', 'NO'); }; // returns a boolean @@ -223,6 +227,9 @@ interface AppConfig { export const getAppState = async (config?: AppConfig) => { try { + + + const data = await fetcher( `https://${process.env.NEXT_PUBLIC_API_DOMAIN}/user` ); @@ -236,6 +243,7 @@ export const getAppState = async (config?: AppConfig) => { return REGISTRED; } } catch (err) { + console.log(err); return SIGNED_OUT; } }; @@ -248,12 +256,15 @@ export const register = async (config?: AppConfig) => { {} ); const user = await data.json(); + + console.log(user); // register analytics if (config) { registerAnalytics(user.analyticsId, config.tagId); } return REGISTRED; } catch (err) { + console.log(err); return SIGNED_OUT; } }; @@ -261,15 +272,38 @@ export const register = async (config?: AppConfig) => { // auth fetcher for api calls export const fetcher = async (url: string) => { const token = await getIdToken(); + + //@ts-ignore + if (token) { + //@ts-ignore + const headers = new Headers({ + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }); + + //@ts-ignore + window.gtag( + 'get', + process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID!, + 'client_id', + (clientId: string) => { + //@ts-ignore + const check = localStorage.getItem('cookies-product'); + //@ts-ignore + if (check === 'YES') { + console.log(clientId); + headers.set('x-client-id', `${clientId}`); + } + } + ); + + console.log(headers.entries()); + //@ts-ignore return fetch(url, { method: 'GET', - //@ts-ignore - headers: new Headers({ - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}`, - }), + headers, }); } else { return Promise.reject(new Error('user not authenticated')); @@ -283,15 +317,33 @@ export const mutator = async ( ) => { const token = await getIdToken(); if (token) { + //@ts-ignore + const headers = new Headers({ + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }); + //@ts-ignore + window.gtag( + 'get', + process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID!, + 'client_id', + (clientId: string) => { + //@ts-ignore + const check = localStorage.getItem('cookies-product'); + + if (check === 'YES') { + console.log(clientId); + headers.set('x-client-id', `${clientId}`); + } + } + ); + //@ts-ignore return fetch(url, { method, body: JSON.stringify(body), //@ts-ignore - headers: new Headers({ - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}`, - }), + headers: headers, }); } else { return Promise.reject(new Error('user not authenticated'));