์ฟ ํก ์ํ ์๋ ๋ ธ์ถ ๋ฐฉ๋ฒ
๋ธ๋ก๊ทธ ๊ธ ๋ด์ฉ๊ณผ ์๋์ผ๋ก ์ฐ๋๋๋ ์ฟ ํก ์ํ ๋ ธ์ถ ๋ฐฉ๋ฒ์ ์๋ดํฉ๋๋ค. ์ ๋ชฉ์ด๋ ์ง์ ํ๊ทธ๋ฅผ ๋ถ์ํด ๊ด๋ จ ์ํ์ ์ค์๊ฐ์ผ๋ก ๋ถ๋ฌ์ ์๋ ๋ฐฐ์นํ๋ ์ค๋งํธ ์๋ํ ๋ฐฉ์์ ๋๋ค.
๋ธ๋ก๊ทธ ์ฝํ
์ธ ์ ์๋ฒฝํ ์ผ์นํ๋ ์ฟ ํก ์ํ์ ์๋์ผ๋ก ๋
ธ์ถํ๋ ๋ฐฉ๋ฒ์ ์๊ฐํฉ๋๋ค. ์ด์ ๋ ์ด์ ์ผ์ผ์ด ์ํ ๋งํฌ๋ฅผ ์ฝ์
ํ๋๋ผ ์๊ฐ์ ๋ญ๋นํ ํ์๊ฐ ์์ต๋๋ค. ์ด ์์คํ
์ ๊ธ ์ ๋ชฉ(h1)์ด๋ ์ง์ ํ๊ทธ(p class="shoptag")๋ฅผ ์ ๊ตํ๊ฒ ๋ถ์ํ์ฌ, ํด๋น ์ฝํ
์ธ ์ ๊ฐ์ฅ ๊ด๋ จ์ฑ ๋์ ์ํ์ ์ค๋งํธํ๊ฒ ๋
ธ์ถํฉ๋๋ค.
1. ์ฃผ์ ๊ธฐ๋ฅ ๋ฐ ์ฅ์
- ์ฝํ ์ธ ๋ง์ถค ์ํ ๋งค์นญ: "์์ดํ๋ผ์ด์ด ์ถ์ฒ" ๊ธ์๋ ์๋์ผ๋ก ๊ด๋ จ ๊ฐ์ ์ํ์ ๋ ธ์ถํฉ๋๋ค.
- ์๋ ์์น ๋ฐฐ์น: ๋
์์ ํ๋ฆ์ ๋ฐฉํดํ์ง ์๋ ์ต์ ์ ์์น(์ฒซ ๋ฒ์งธ
h3ํ๊ทธ ๋ค์)์ ์๋ ์ฝ์ ๋ฉ๋๋ค. - ์ค๋งํธ ํํฐ๋ง: ๋ฉ์ธ์ด๋ ์นดํ ๊ณ ๋ฆฌ ํ์ด์ง์์๋ ๋นํ์ฑํ๋์ด ๋ธ๋ก๊ทธ ํ์ง์ ์ ์งํฉ๋๋ค.
- ๋ฐ์ํ ๋์์ธ: ๋ฐ์คํฌํฑ 3์ด ๊ทธ๋ฆฌ๋, ๋ชจ๋ฐ์ผ ๊ฐ๋ก ์ฌ๋ผ์ด๋ ๋ฐฉ์์ผ๋ก ๊ด๊ณ ํจ๊ณผ๋ฅผ ๊ทน๋ํํฉ๋๋ค.
2. ์ฟ ํก ์ํ ์๋ํ ์ ์ฉ ๋ฐฉ๋ฒ (7๋จ๊ณ)
1๋จ๊ณ: ํด๋ผ์ด์ธํธ ์คํฌ๋ฆฝํธ ์ค์น
์๋ ์คํฌ๋ฆฝํธ๋ฅผ ๋ธ๋ก๊ทธ ์คํจ์ body ํ๋จ์ ์ฝ์
ํฉ๋๋ค.
script
const API_URL = 'https://๋ณธ์ธ์_์ฑ์ค_์คํฌ๋ฆฝํธ_URL';
const DEFAULT_LIMIT = 3;
document.addEventListener('DOMContentLoaded', function () {
const path = window.location.pathname;
if (path === '/' || path.startsWith('/category')) return;
searchProductsAndInsert();
});
function searchProductsAndInsert() {
const tagElement = document.querySelector('p.shoptag');
const h1Element = document.querySelector('h1');
let keyword = tagElement?.textContent.trim() || h1Element?.textContent.split('-')[0].trim();
if (!keyword) return;
const resultsContainer = document.createElement('div');
resultsContainer.id = 'coupangProductContainer';
const firstH3 = document.querySelector('h3');
if (firstH3) firstH3.parentNode.insertBefore(resultsContainer, firstH3.nextSibling);
fetch(`${API_URL}?keyword=${encodeURIComponent(keyword)}&limit=${DEFAULT_LIMIT}`)
.then(res = res.json())
.then(data = {
if (data.data?.productData) {
displayResults(data.data.productData, resultsContainer);
addAffiliateDisclaimer(resultsContainer);
}
});
}
function displayResults(products, container) {
products.forEach(p = {
const card = document.createElement('div');
card.className = 'product-card';
card.innerHTML = `
img src="${p.productImage}" class="product-image"
div class="product-title"${p.productName}/div
div class="product-price"${p.productPrice.toLocaleString()}์/div
a href="${p.productUrl}" target="_blank" class="product-link"์ฟ ํก์์ ๋ณด๊ธฐ/a`;
container.appendChild(card);
});
}
function addAffiliateDisclaimer(container) {
const p = document.createElement('p');
p.className = 'coupang-disclaimer';
p.textContent = 'โป ์ด ๊ด๊ณ ๋ ์ฟ ํก ํํธ๋์ค ํ๋์ ์ผํ์ผ๋ก, ์ด์ ๋ฐ๋ฅธ ์ผ์ ์ก์ ์์๋ฃ๋ฅผ ์ ๊ณต๋ฐ์ต๋๋ค.';
container.after(p);
}
/script
2๋จ๊ณ: ์ค์ ํญ๋ชฉ ๊ฐ์ด๋
| ํญ๋ชฉ | ์ค๋ช | ์ฌ์ฉ ์์ |
|---|---|---|
| API_URL | ๊ตฌ๊ธ ์ฑ์ค ์คํฌ๋ฆฝํธ ๋ฐฐํฌ ์ฃผ์ | https://script.google.com/.../exec |
| shoptag | ์๋ ํค์๋ ์ง์ ํ๊ทธ | p class="shoptag"์์ดํ๋ผ์ด์ด/p |
3. ๊ตฌ๊ธ ์ฑ์ค ์คํฌ๋ฆฝํธ(Backend) ์ฐ๋
์ฟ ํก API ํต์ ์ ์ํ ์๋ฒ ์ธก ์ฝ๋๋ฅผ ์์ฑํฉ๋๋ค. ๋ฐ๋์ ๋ณธ์ธ์ API Key๋ฅผ ์ ๋ ฅํ์ธ์.
const COUPANG_ACCESS_KEY = "YOUR_ACCESS_KEY";
const COUPANG_SECRET_KEY = "YOUR_SECRET_KEY";
function doGet(e) {
const keyword = e.parameter.keyword;
const limit = e.parameter.limit || 3;
const result = fetchCoupangProducts(limit, keyword);
return ContentService.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
// (์์ธ API ํธ์ถ ๋ก์ง์ ๊ธฐ์กด ๊ฐ์ด๋์ ๋์ผํ๊ฒ ์ ์ง)
4. ๋ฐ์ํ ๋์์ธ ์คํ์ผ (CSS)
๋คํฌ ๋ชจ๋์ ๋ผ์ดํธ ๋ชจ๋์ ์ต์ ํ๋ ๋ฐ์ํ ์นด๋ ์คํ์ผ์ ๋๋ค.
#coupangProductContainer { display: flex; gap: 20px; flex-wrap: wrap; }
.product-card { flex: 1 1 calc(33.3% - 20px); border: 1px solid #ddd; padding: 10px; border-radius: 8px; text-align: center; }
@media (max-width: 768px) {
#coupangProductContainer { flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x mandatory; }
.product-card { flex: 0 0 80%; }
}
์ง๋ฌธ 1: ์ฟ ํก ์๋ ์ํ ๋ ธ์ถ ์์คํ ์ ์ด๋ป๊ฒ ์๋ํ๋์?
๋ธ๋ก๊ทธ ๊ธ์ ์ ๋ชฉ(h1)์ด๋ ์๋ ์ง์ ํ๊ทธ(p class="shoptag")๋ฅผ ๋ถ์ํด ํด๋น ์ฝํ ์ธ ์ ๊ฐ์ฅ ๊ด๋ จ์ฑ ๋์ ์ฟ ํก ์ํ์ ์๋์ผ๋ก ์ถ์ฒํด์ฃผ๋ ์์คํ ์ ๋๋ค. ๋ณ๋์ ์๋ ์์ ์์ด ์ต์ ์ธ๊ธฐ ์ํ์ ์ค์๊ฐ์ผ๋ก ๋ ธ์ถํ์ฌ ๊ด๋ฆฌ์ ์ด์ ํจ์จ์ฑ์ ๋์ฌ์ค๋๋ค.
์ง๋ฌธ 2: ์๋์ผ๋ก ์ํ์ด ์ฝ์ ๋๋ ์์น๋ฅผ ๋ณ๊ฒฝํ ์ ์๋์?
๋ค, ๊ธฐ๋ณธ์ ์ผ๋ก ๋ณธ๋ฌธ ๋ด ์ฒซ ๋ฒ์งธ h3 ํ๊ทธ ๋ค์์ ์ฝ์ ๋๋๋ก ์ค์ ๋์ด ์์ต๋๋ค. ์คํฌ๋ฆฝํธ ๋ด์ 'querySelector('h3')' ๋ถ๋ถ์ ๋ค๋ฅธ ํ๊ทธ๋ ํด๋์ค๋ช ์ผ๋ก ๋ณ๊ฒฝํ๋ฉด ์ํ๋ ์์น๋ก ์์ ๋กญ๊ฒ ์กฐ์ ์ด ๊ฐ๋ฅํฉ๋๋ค.
์ง๋ฌธ 3: ์์คํ ๋์ ์ ์ฃผ์ํด์ผ ํ ์ ์ฑ ์ ์ฌํญ์ ๋ฌด์์ธ๊ฐ์?
์ฟ ํก ํํธ๋์ค ์ด์ ์ ์ฑ ์ ๋ฐ๋ผ '์์๋ฃ ์ ๊ณต' ์๋ด ๋ฌธ๊ตฌ(๋์คํด๋ ์ด๋จธ)๋ ๋ฐ๋์ ๋ ธ์ถ๋์ด์ผ ํฉ๋๋ค. ๋ํ ๊ณผ๋ํ API ํธ์ถ์ ์ ํ๋ ์ ์์ผ๋ฏ๋ก ๋ถ๋น ํธ์ถ ํ์๋ฅผ ์กฐ์ ํ์ฌ ์์ ์ ์ผ๋ก ์ด์ํ๋ ๊ฒ์ด ์ค์ํฉ๋๋ค.