Skip to content

Commit

Permalink
fix: utm phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimNikalayeu committed Dec 26, 2023
1 parent 77fbe38 commit fb92b07
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
11 changes: 11 additions & 0 deletions firebase-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const firebaseConfig = {
apiKey: "AIzaSyCRpHkB3tswbonEIcVHBtJbPIb385uU3G0",
authDomain: "iksha-country-club.firebaseapp.com",
databaseURL: "https://iksha-country-club-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "iksha-country-club",
storageBucket: "iksha-country-club.appspot.com",
messagingSenderId: "149220009714",
appId: "1:149220009714:web:c751f9e8ab961a9e10d26b"
}

export default firebaseConfig;
29 changes: 29 additions & 0 deletions firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import firebaseConfig from './firebase-config.js';
import {initializeApp} from 'firebase/app';
import { getDatabase, ref, get } from 'firebase/database';

const app = initializeApp(firebaseConfig);

export const db = getDatabase(app);

export const fetchData = async (groupID, setState) => {
try {
const groupsRef = ref(db, 'groups');
const snapshot = await get(groupsRef);

if (snapshot.exists()) {

snapshot.forEach((childSnapshot) => {
const childData = childSnapshot.val();
if (childData.groupId === groupID) {
setState(childData.substt);
}
});
} else {
console.log('Группа с указанным groupID не найдена.');
}
} catch (error) {
console.error('Ошибка при получении данных из Firebase:', error);
}
};

22 changes: 6 additions & 16 deletions src/common/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const slideVariants = {
},
}
const Footer = ({ className }) => {
const { utm_source } = useURLData()
const { utm_source, phoneContent } = useURLData();
const matchingPhone = phoneContent.find(item => item.utm === utm_source);
const phoneNumber = matchingPhone ? '+' + matchingPhone.phone : '+74995055031';
return (
<div className={`${className || ""}`}>
<div className="wrapper ">
Expand Down Expand Up @@ -49,27 +51,15 @@ const Footer = ({ className }) => {
}}
initial="initial"
animate="animate"
href={utm_source === 'yandex' ? 'tel:+74995055067' : utm_source === 'vkontakte' ? 'tel:+74995055087' : 'tel:+74995055031'}
href={`tel:${phoneNumber}`}
>
<img className="z-10 h-9 w-9" src={phone} alt="" />
</motion.a>
</div>
</div>
{
utm_source === 'yandex' ?
<a href={'tel:+74995055067'} className="min-w-[160px] text-white">
+7(499) 505-50-67
</a>
: utm_source === 'vkontakte' ?
<a href={'tel:+74995055087'} className="min-w-[160px] text-white">
+7(499) 505-50-87
</a>
:
<a href={"tel:+74995055031"} className="min-w-[160px] text-white">
+7(499) 505-50-31
<a href={`tel:${phoneNumber}`} className="min-w-[160px] text-white">
{phoneNumber}
</a>

}
</div>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/components/Home/Bron.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ const OpenLeft = {
}

const Bron = () => {
const { utm_source } = useURLData()
const { utm_source, phoneContent } = useURLData();
const matchingPhone = phoneContent.find(item => item.utm === utm_source);
const phoneNumber = matchingPhone ? '+' + matchingPhone.phone : '+74995055031';


const bronData = [
{
imgAvif: "/image/wa_bl.avif",
imgWebp: "/image/wa_bl.webp",
imgAltText: "Позвонить",
text: utm_source === 'yandex' ? "+7(499) 505-50-67" : utm_source === 'vkontakte' ? "+7(499) 505-50-87" : "+7 (499) 505-50-31",
link: utm_source === 'yandex' ? "tel:+74995055067" : utm_source === 'vkontakte' ? "tel:+74995055087" : "tel:+74995055031",
text: phoneNumber,
link: `tel:${phoneNumber}`,
},
{
imgAvif: "/image/tg_bl.avif",
Expand Down
9 changes: 9 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import "./fonts.css"
import "./fonts/Lato-Regular.ttf"
import "./fonts/MontserratAlternates-Regular.ttf"
import "./index.css"
import {useURLData} from 'utils/URLData';
import {fetchData} from '../firebase.js';

ReactDOM.createRoot(document.getElementById("root")).render(
<BrowserRouter>
Expand Down Expand Up @@ -38,6 +40,13 @@ function AppWithDelay() {
// console.log(window.location.search)
// console.log(window.location.search.includes('?korpOpen=1'))

const { updatePhoneContent } = useURLData();
const groupID = -1002014846298;

useEffect(() => {

fetchData(groupID, updatePhoneContent)
}, [updatePhoneContent])


const [windowWidth, setWindowWidth] = useState(window.innerWidth)
Expand Down
4 changes: 3 additions & 1 deletion src/utils/URLData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export const useURLData = create((set) => ({
utm_source: '',
utm_campaign: '',
utm_content: '',
updateData: (source, campaign, content) => set({ utm_source: source, utm_campaign: campaign, utm_content: content })
updateData: (source, campaign, content) => set({ utm_source: source, utm_campaign: campaign, utm_content: content }),
phoneContent: [],
updatePhoneContent: (newPhoneContent) => set({ phoneContent: newPhoneContent }),
}));

export const URLData = {
Expand Down

0 comments on commit fb92b07

Please sign in to comment.