Craft FunctionsใจCraft Counterใงๅฝใใไธ้ๆฐใฎใใใใๅผใๆฝ็ญใๅฎ่ฃ ใใ
Craft FunctionsใจCraft Counterใๅฉ็จใใฆๅฝใใไธ้ๆฐใ่ๆ ฎใใใใๅผใๆฝ็ญใๅฎ่ฃ ใใๆนๆณใซใคใใฆ็ดนไปใใพใใ
- Soichiro Yamaguchi
- Solution
- 10 May, 2024
ใใใซใกใฏใCustomer Engineerใฎๅฑฑๅฃใงใ๏ผๅ ๆฅใๅๆขๅตใณใใณใฎๅๅ ด็ๆๆฐไฝใ่ฆณใซ่กใใพใใใใฉในใ3ๅใง้ฉใใฎๆฐไบๅฎใใปใปใปใๅพนๅคใงไบ็ฟใใใใใใงใใจใฆใๆฅฝใใใพใใ๏ผ
ใใฆๆฌ่จไบใงใฏใKARTEใฎๆฅๅฎขใตใผใในใจCraftใ็ตใฟๅใใใฆใไธ้ใ่จญๅฎใใใๅฝใใๆฐใๆใคใใๅผใๆฝ็ญใฎๅฎ่ฃ ใใๆนๆณใใ็ดนไปใใพใใ
KARTEใฎๆจๆบๆฉ่ฝใฎใฟใไฝฟ็จใใฆใใๅผใใขใฏใทใงใณใๅฎ่ฃ ใใๅ ดๅใๅฝใใใๅบใๅๆฐใใซใฆใณใใใใใจใๅฐ้ฃใงใใใใจใใซใฆใณใใงใใใจใใฆใใไธ้ๆฐใซ้ใใ้ใซ้ฉๅใช้็ฅใ่กใใๆ ๅฝ่ ใใฟใคใ ใชใผใซใขใฏใทใงใณใๅๆญขใใใใชใใฌใผใทใงใณใๅฟ ่ฆใซใชใใพใใ
ใใใใCraft FunctionsใจCraft Counterใๆดป็จใใใใจใงใๅฝใใใๅบใๅๆฐใ่ชๅใง้่จใใๅฝใใใไธ้ๆฐใซ้ใใๅ ดๅใซไฝใใใฎๅฆ็ใ่กใใใใชใขใฏใทใงใณใๅฎ่ฃ ใงใใพใใ
ใใฎๆนๆณใ็จใใใใจใงใ้็จใฎๆ้ใๅๆธใใคใคใใฆใผใถใผใซ้ฉๅใชใใๅผใๆฝ็ญใๆไพใใใใจใๅฏ่ฝใซใชใใพใใๆฌ่จไบใงใฏใใใฎๅ ทไฝ็ใชๅฎ่ฃ ๆ้ ใซใคใใฆ่ฉณใใใ็ดนไปใใพใใ
ใขใฆใใใใใคใกใผใธ
ๆฌ่จไบใง็ดนไปใใใใๅผใๆฝ็ญใฎๆ็ต็ใชใขใฆใใใใใฏใไปฅไธใฎใคใกใผใธๅณใฎ้ใใงใใ
ใใฎใคใกใผใธใฏใใฆใผใถใผใใ่ฆใใใใๅผใใฎ็ตๆ็ป้ขใ่กจใใฆใใใๅฝใใใใใบใฌใ็ดๆ็ใซ็่งฃใงใใๆฅๅฎขใขใฏใทใงใณใซใชใฃใฆใใพใใ
ใใใซใใทในใใ ใฎๅ จไฝๆงๆใ็คบใใๅณใไปฅไธใซ็คบใใพใใ
ใใฎๅณใฏใใฆใผใถใผใฎใขใฏใทใงใณใซๅบใฅใใฆCraft Functionsใใฉใฎใใใซๅไฝใใๅฝใใใๅบใๅๆฐใ็ฎก็ใใคใคใ็ตๆใจใใฆๅฝใใใพใใฏใใบใฌใ่ฟใใฎใใ็คบใใฆใใพใใ
ๆณจๆ็น
ใใฎๆฝ็ญใๅฎๆฝใใๅใซใไปฅไธใฎ็นใซๆณจๆใใฆใใ ใใใ
-
CraftใฎGrowthใใฉใณไปฅไธใๅฉ็จใใฆใใใใจใๅๆใจใใฆใใพใใ
-
ๅฎ้ใซใใๅผใๆฝ็ญใ่กใ้ใซใฏใใใๅผใAPIใฎไธๆญฃๅฉ็จใ้ฒใใใใซ่ช่จผใทในใใ ใจใฎ้ฃๆบ็ญใๆค่จใใฆใใ ใใใ
-
ๆฌ่จไบใงใฏใๅไธใฆใผใถใผใใใๅผใใซๅๅ ใงใใใฎใฏ่จญๅฎใใๆ้้้ใซ1ๅใซใใใใจใงใ็ฐกๆ็ใซไธๆญฃๅฉ็จใ้ฒใใใใช่จญๅฎใจใใฆใใพใใ
-
ๅฝ้ธใฆใผใถใผใฎไธ่ฆงใๆฝๅบใใใๅ ดๅใDatahubใฎๅฅ็ดใๅฟ ่ฆใซใชใใพใ
-
ๅฝ้ธใฆใผใถใผใฎ็ฎก็ใใ/track/event/write API็ต็ฑใง็บ็ใใใKARTEใฎใคใใณใใงๅฎๆฝใใพใใAPIใฎๅ้ใชใฏใจในใๅถ้ใ่ถ ใใๅ ดๅใฏใไธ้ใๅผใไธใใๅฟ ่ฆใใใใพใ
-
ๅฎ้ใซใใฎใใใชๆฝ็ญใ้็จใใๅ ดๅใซใฏใๆฏๅ่กจ็คบๆณใฎ่ฆณ็นใใใๅฝใใๆฎๆฐใ0ใซใชใฃใๆ็นใง้ใใใซใญใฃใณใใผใณใ็ตไบใใฆใใ ใใใ
่จญๅฎๆ้
่จญๅฎใฎๆ้ ใฏๆฌกใฎ้ใใงใใ
- API v2 ใขใใชใไฝๆใใ
- API v2 ใขใใชใฎ ใขใฏใปในใใผใฏใณใ Craft Secret Manager ใซ็ป้ฒใใ
- Craft Functionsใฎใใกใณใฏใทใงใณใไฝๆใใ
- Craft Functionsใฎใจใณใใใคใณใใไฝๆใใ
- ใปใฐใกใณใใไฝๆใใ
- ๆฅๅฎขใตใผใในใไฝๆใใ ้ ็ชใซ่ฆใฆใฟใพใใใใ
1. API v2 ใขใใชใไฝๆใใ
KARTEใฎAPIใๅฉ็จใใใใใซใAPI v2ใขใใชใไฝๆใใพใใ
- ในใใข > API v2่จญๅฎ ใใใขใใชใๆฐ่ฆไฝๆ
- ใขใใชใฟใคใ ใ token ใซ่จญๅฎ
-
ๅฟ ่ฆใชscopeใ่ฟฝๅ
-
track.event.write
-
ใขใใชใไฟๅญใใไธๅบฆใ ใ่กจ็คบใใใใขใฏใปในใใผใฏใณใใกใขใใฆใใ
2. API v2 ใขใใชใฎ ใขใฏใปในใใผใฏใณใ Craft Secret Manager ใซ็ป้ฒใใ
API v2 ใขใใชใฎใขใฏใปในใใผใฏใณใCraft Functionsใใๅฎๅ จใซๅฉ็จใใใใใซใCraft Secret Manager ใซ็ป้ฒใใพใใ
- Craft > ใทใผใฏใฌใใ ใใใทใผใฏใฌใใใๆฐ่ฆไฝๆ
- ๅๅ ใซใใใใใใใๅๅใๅ ฅๅ
- ใกใขใใฆใใใAPI v2 ใขใใชใฎใขใฏใปในใใผใฏใณใ ใทใผใฏใฌใใใฎๅค ใซๅ ฅๅใใไฝๆ
- ใทใผใฏใฌใใๅใใกใขใใฆใใ
3. Craft Functionsใฎใใกใณใฏใทใงใณใไฝๆใใ
Craft Functionsใฎใใกใณใฏใทใงใณใไฝๆใใพใใไฝๆๆ้ ใฏๆฌกใฎ้ใใงใใ
-
Craft > ใใกใณใฏใทใงใณ > ๆฐ่ฆไฝๆ > ใใณใใฌใผใใใไฝๆ ใ้ธๆ
-
ใ Craft FunctionsใจCraft Counterใงๅฝใใไธ้ๆฐใฎใใใใๅผใๆฝ็ญใๅฎ่ฃ ใใ ใใจใใใใณใใฌใผใใๆค็ดขใๅๅพใใฟใณใใฏใชใใฏ
-
ๅๆ ใใฟใณใใฏใชใใฏ
-
ๅคๆฐ ใฟใใงๆฌกใฎๅคๆฐใฎๅคใ่จญๅฎใใ
-
PRIZES
-
ๅฝใใ็จฎๅฅใฎๅ็งฐใ่จญๅฎใใพใใใซใณใๅบๅใใง่คๆฐๆๅฎๅฏ่ฝใงใใ
-
ไพ: 1็ญ,2็ญ,3็ญ
-
LIMITS
-
ๅฝใใใฎไธ้ๆฐใ่จญๅฎใใพใใใซใณใๅบๅใใง่คๆฐๆๅฎๅฏ่ฝใงใPRIZESใจๅใ้ ็ชใงๅฏพๅฟใใไธ้ๆฐใ่จญๅฎใใพใใ
-
ไพ: 10,50,100
-
LOSE_PROBABILITY
-
ใใบใฌใฎ็ขบ็ใ่จญๅฎใใพใใ0ใใ1ใฎ้ใฎๅฐๆฐๅคใงๆๅฎใใพใใ
-
ไพ: 0.5
-
USER_PARTICIPATION_INTERVAL_MINUTES
-
ๅไธใฆใผใถใผใใใๅผใใซ้ฃ็ถใใฆๅๅ ใงใใชใๆ้ใๅๅไฝใง่จญๅฎใใพใใ0ใๆๅฎใใใจๅถ้ใชใใซใชใใพใใ
-
KARTE_APP_TOKEN_SECRET
-
ๆ้ 2ใงใกใขใใKARTE API v2ใขใใชใฎใขใฏใปในใใผใฏใณใฎใทใผใฏใฌใใๅใ่จญๅฎใใพใใ
-
ใใฎไปใฎๅคๆฐใฏใใฒใจใพใใใใฉใซใๅคใฎใพใพใงๅ้กใใใพใใ
-
ไฟๅญ ใใ
-
ใใใญใคๅฎไบๅพใ่จญๅฎ > ใใกใณใฏใทใงใณใฎๆๅนๅ ใซใใงใใฏใไปใใ
ๅฝใใๅคๅฎใฎใญใธใใฏใซใคใใฆ
ใใฎใใณใใฌใผใใซใใใๅฝใใ/ใฏใใใๅคๅฎใใใญใธใใฏใซใคใใฆ่ชฌๆใใพใใๅ่ณๅใฎๅฝใใ็ขบ็ใฏใๆฌกใฎใใใซ่จ็ฎใใใพใ๏ผ
- ใใฎ่ณๅใฎๅฝใใๆฎๆฐ / ๅ จไฝใฎๅฝใใๆฎๆฐ * (1 - ใฏใใ็ขบ็)
ๆฌกใฎใใใช็ถๆณใๅ ทไฝไพใจใใฆๆณๅฎใใพใ๏ผ
- PRIZES: 1็ญ,2็ญ,3็ญ
- LIMITS: 10,50,100
- LOSE_PROBABILITY: 0.5
ๅๆ็ถๆ ใงใฎ็ขบ็ใฏใๆฌกใฎ้ใใงใ๏ผ
-
ใฏใใใฎ็ขบ็: 0.5
-
ๅฝใใใฎ็ขบ็: 0.5
-
ๅ ใ1็ญใฎๅฝ้ธ็ขบ็: 10 / (10 + 50 + 100) * 0.5 โ 0.031 (็ด3.1%)
-
ๅ ใ2็ญใฎๅฝ้ธ็ขบ็: 50 / (10 + 50 + 100) * 0.5 โ 0.156 (็ด15.6%)
-
ๅ ใ3็ญใฎๅฝ้ธ็ขบ็: 100 / (10 + 50 + 100) * 0.5 โ 0.313 (็ด31.3%)
ใใจใใฐ1็ญใๆฎใ6ๅใ2็ญใๆฎใ15ๅใ3็ญใๆฎใ40ๅใซใชใฃใๅ ดๅใฎ็ขบ็ใฏๆฌกใฎ้ใใงใ๏ผ
-
ใฏใใใฎ็ขบ็: 0.5
-
ๅฝใใใฎ็ขบ็: 0.5
-
ๅ ใ1็ญใฎๅฝ้ธ็ขบ็: 6 / (6 + 15 + 40) * 0.5 โ 0.049 (็ด4.9%)
-
ๅ ใ2็ญใฎๅฝ้ธ็ขบ็: 15 / (6 + 15 + 40) * 0.5 โ 0.123 (็ด12.3%)
-
ๅ ใ3็ญใฎๅฝ้ธ็ขบ็: 40 / (6 + 15 + 40) * 0.5 โ 0.328 (็ด32.8%)
ใใใซใใใๅ็ใซๅๅฝใใใฎ็ขบ็ใๅคๅใใพใใ ๅฝใใๆฎๆฐใ็กใใชใฃใ่ณๅใฏ่ชๅใงๅฝใใ็ขบ็ใ0ใซใชใใใใๅฝใใใชใใชใใพใใ
ใชใใใใณใใฌใผใใฎใฝใผในใณใผใใฏGitHubใงๅ ฌ้ใใฆใใพใใ
craft-codes/craft-functions/lottery-with-limits-of-wins at main ยท plaidev/craft-codes
4. Craft Functionsใฎใจใณใใใคใณใใไฝๆใใ
ไฝๆใใใใกใณใฏใทใงใณใๅค้จใใๅฎ่กใงใใใใใซใใใใใฎใจใณใใใคใณใใไฝๆใใพใใ
- ไฝๆใใใใกใณใฏใทใงใณใฎ็ทจ้็ป้ขใใ ่จญๅฎ > ใจใณใใใคใณใ > ไฝๆ ใใฏใชใใฏ
- ่กจ็คบใใใใจใณใใใคใณใURLใใกใขใใฆใใ
5. ๆฅๅฎขใตใผใในใไฝๆใใ
ใใๅผใๆฉ่ฝใใฆใผใถใผใซๆไพใใใใใซใKARTEใฎๆฅๅฎขใขใฏใทใงใณใๅฉ็จใใฆใใใๅผใ็ป้ขใใใใใขใใๅฝขๅผใงไฝๆใใพใใ ใใฎใใใใขใใใฏใ่จญๅฎใใๆ้ๅ ใซใใๅผใใซๅๅ ใใฆใใชใใฆใผใถใผใซๅฏพใใฆ่กจ็คบใใใพใใ
ใใๅผใใขใฏใทใงใณใฎJavaScriptๅฎ่ฃ
ไปฅไธใฎJavaScriptใณใผใใฏใใฆใผใถใผใใใใใๅผใใใใฟใณใใฏใชใใฏใใ้ใซๅฎ่กใใใพใใ ใใฎใณใผใใฏใใใๅผใใฎใชใฏใจในใใ้ไฟกใใๅฝใใ/ใใบใฌใฎ็ตๆใซๅฟใใฆstateใๆดๆฐใใพใใ CRAFT_ENDPOINT_URLใฏๆ้ 4ใงใกใขใใใจใณใใใคใณใURLใซ็ฝฎใๆใใฆใใ ใใใ LOTTERY_KEYใฏใใๅผใๆฝ็ญๅๅฃซใๅบๅฅใใใใใฎ่ญๅฅๅญใงใใๅฝใใๆใฎใคใใณใ็ญใซๅซใพใใพใใ
var CRAFT_ENDPOINT_URL = “https://xxx.cev2.karte.io/functions/yyyyy";var LOTTERY_KEY = “lottery_key”;widget.setVal(“isLoading”, false);widget.method(“onClick”, function () { // Display loading indicator until the request is complete widget.setVal(“isLoading”, true); // Send the lottery request fetchData(function (item, error) { if (error) { console.error(error); widget.setState(3); // State for error: not winning } else { widget.setVal(“result”, item.result); // Change the state based on whether a prize was won if (item.result && item.result !== “No prize won”) { widget.setState(2); // State for winning } else { widget.setState(3); // State for not winning } } widget.setVal(“isLoading”, false); });});function fetchData(cb) { var payload = { userId: “#{user_id}”, lotteryKey: LOTTERY_KEY, }; fetch(CRAFT_ENDPOINT_URL, { method: “POST”, headers: { “Content-Type”: “application/json”, }, body: JSON.stringify(payload), }) .then(function (response) { return response.json(); }) .then(function (item) { cb(item); }) .catch(function (err) { cb(null, err); });}widget.show();
ใใๅผใใใใใขใใใฎๅฎ่ฃ
ใใๅผใใฎ็ตๆใซๅฟใใฆ่กจ็คบใใใๆฅๅฎขใตใผใในใฏไปฅไธใฎ้ใใงใใ ใฆใผใถใผใใใใใๅผใใใใฟใณใใฏใชใใฏใใใจใJavaScriptใCraft Functionsใธใชใฏใจในใใ้ไฟกใใ็ตๆใซๅฟใใฆๅฝใใใพใใฏใใบใฌใฎ็ป้ขใ่กจ็คบใใใพใใ
<div class=“karte-temp-whole”> <div class=“karte-temp-state1” krt-if=“state==1”> <i class=“karte-temp-close karte-close karte-temp-hover” krt-if=”#{close.use}"></i> <div class=“karte-temp-card”> <div class=“karte-temp-mainvisual”><img src="#{mainvisual}" alt="#{mainvisual_alt}" /></div> <div class=“karte-temp-wrap”> <div class=“karte-temp-title”>#{title}</div> <div class=“karte-temp-description”>#{description}</div> <a class=“karte-temp-btn karte-temp-hover” krt-on:click=“onClick”> <span krt-if="!isLoading">#{btn}</span> <div krt-else class=“drawing”> <i class=“loader” aria-hidden=“true”></i> #{loading_btn} </span> </a> </div> </div> </div> <div class=“karte-temp-state1” krt-if=“state==2”> <i class=“karte-temp-close karte-close karte-temp-hover” krt-if="#{close.use}"></i> <div class=“karte-temp-card”> <div class=“karte-temp-mainvisual”><img src="#{winvisual}" alt="#{winvisual_alt}" /></div> <div class=“karte-temp-wrap”> <div class=“karte-temp-title”>{{result}}#{win_title}</div> </div> </div> </div> <div class=“karte-temp-state1” krt-if=“state==3”> <i class=“karte-temp-close karte-close karte-temp-hover” krt-if="#{close.use}"></i> <div class=“karte-temp-card”> <div class=“karte-temp-mainvisual”><img src="#{losevisual}" alt="#{losevisual_alt}" /></div> <div class=“karte-temp-wrap”> <div class=“karte-temp-title”>#{lose_title}</div> </div> </div> </div></div>ๅฎ้ใซใฏๆฅๅฎขใตใผใในใ้ ไฟกใใใ็ถๆณใซๅใใใ้ ไฟก่จญๅฎใๅฎๆฝใใฆใใ ใใใ
ๅฎ้ใซๅใใใฆใฟใ
่จญๅฎใๅฎไบใใใใๅฎ้ใซๅไฝใ็ขบ่ชใใฆใฟใพใใใใ
ใพใใฏใใใใๅผใใใฟใณใๆผไธใใใจใใใใๅงใใพใใใใๅผใใๅงใพใใ็ตๆใ่กจ็คบใใใใใญใปในใไปฅไธใฎ็ปๅใง็ขบ่ชใงใใพใใ
ๆฌกใซใ่จญๅฎใๅคๆดใใฆใๅฝใใใฎไธ้ๆฐใ0ใซใใฆใฟใพใใใใใซใใใใในใฆใฎใฆใผใถใผใใใบใฌใซใชใใฏใใงใใ
ไธ่จใฎ่จญๅฎๅคๆดๅพใๅๅบฆใใใๅผใใใฟใณใๆผไธใใใจใไปฅไธใฎใใใซใใบใฌใๅบใใใจใ็ขบ่ชใงใใพใใ
ใใๅผใๆฉ่ฝใฎๅไฝ็ขบ่ชใ่กใใฆใ่จญๅฎใซๅฟใใ็ตๆใๅพใใใใใจใใใใใพใใใ
ใใๅผใใคใใณใใฎ้ไฟกใซใคใใฆ
ใใๅผใใใใใจใๅฝใใใใใบใฌใฎ็ตๆใซๅฟใใฆใคใใณใใFunctionsใใ้ไฟกใใใพใใ
- ๅฝใใใฎใคใใณใ:
- ใใบใฌใฎใคใใณใ:
ไพใใฐใ้็จไธใงๅฝใใใฆใผใถใผใฎไธ่ฆงใๆฝๅบใใใๅ ดๅใชใฉใๅฏพ่ฑก่ ใDatahubใฏใจใชใงๆฝๅบใใใใจใๅฏ่ฝใงใใ
ใใใใซ
ๆฌ่จไบใงใฏใCraft FunctionsใจCraft Counterใไฝฟใฃใฆใๅฝใใไธ้ๆฐใ่ๆ ฎใใใใๅผใๆฝ็ญใฎไฝใๆนใใ็ดนไปใใพใใใ
ไปๅใฎใฝใชใฅใผใทใงใณใงใฏๅฝใใ็ขบ็ใๅฝใใๆฎๆฐใซๅฟใใฆๅคๅใใใใใใไบๅฎใใฆใใๆฐใใๅฝใใๆฐใๅบใใฆใใพใฃใใใจใใไบๆ ใใ้็จใฎๆ้ใใใใใซ่ชๅใง้ฟใใใใจใใงใใพใใ
ใใฌใคใใงใฏใไธใฎไธญใซใคใณใใฏใใไธใใๆฐใใใฝใชใฅใผใทใงใณใไธ็ทใซใคใใไปฒ้ใๅ้ใใฆใใพใ๏ผใใฒๆฐ่ปฝใซใๅใๅใใใใ ใใใ
โ ใใผใใใผไผๆฅญใซใชใใใ
- CustomerData-Driven Solution ใไธ็ทใซๅตใใพใใใ๏ผ | PLAID Ecosystem
โ PLAIDใงๅใใใ
- Customer Engineer | ๅ้ใใธใทใงใณ | ๆ ชๅผไผ็คพใใฌใคใ
- Product Engineer | ๅ้ใใธใทใงใณ | ๆ ชๅผไผ็คพใใฌใคใ
ๆฌ่จไบใง็ดนไปใใใใๅผใๆฝ็ญใฎๆ็ต็ใชใขใฆใใใใใฏใไปฅไธใฎใคใกใผใธๅณใฎ้ใใงใใ
ใใฎใคใกใผใธใฏใใฆใผใถใผใใ่ฆใใใใๅผใใฎ็ตๆ็ป้ขใ่กจใใฆใใใๅฝใใใใใบใฌใ็ดๆ็ใซ็่งฃใงใใๆฅๅฎขใขใฏใทใงใณใซใชใฃใฆใใพใใ
ใใใซใใทในใใ ใฎๅ จไฝๆงๆใ็คบใใๅณใไปฅไธใซ็คบใใพใใ
ใใฎๅณใฏใใฆใผใถใผใฎใขใฏใทใงใณใซๅบใฅใใฆCraft Functionsใใฉใฎใใใซๅไฝใใๅฝใใใๅบใๅๆฐใ็ฎก็ใใคใคใ็ตๆใจใใฆๅฝใใใพใใฏใใบใฌใ่ฟใใฎใใ็คบใใฆใใพใใ
ๆณจๆ็น
ใใฎๆฝ็ญใๅฎๆฝใใๅใซใไปฅไธใฎ็นใซๆณจๆใใฆใใ ใใใ
-
CraftใฎGrowthใใฉใณไปฅไธใๅฉ็จใใฆใใใใจใๅๆใจใใฆใใพใใ
-
ๅฎ้ใซใใๅผใๆฝ็ญใ่กใ้ใซใฏใใใๅผใAPIใฎไธๆญฃๅฉ็จใ้ฒใใใใซ่ช่จผใทในใใ ใจใฎ้ฃๆบ็ญใๆค่จใใฆใใ ใใใ
-
ๆฌ่จไบใงใฏใๅไธใฆใผใถใผใใใๅผใใซๅๅ ใงใใใฎใฏ่จญๅฎใใๆ้้้ใซ1ๅใซใใใใจใงใ็ฐกๆ็ใซไธๆญฃๅฉ็จใ้ฒใใใใช่จญๅฎใจใใฆใใพใใ
-
ๅฝ้ธใฆใผใถใผใฎไธ่ฆงใๆฝๅบใใใๅ ดๅใDatahubใฎๅฅ็ดใๅฟ ่ฆใซใชใใพใ
-
ๅฝ้ธใฆใผใถใผใฎ็ฎก็ใใ/track/event/write API็ต็ฑใง็บ็ใใใKARTEใฎใคใใณใใงๅฎๆฝใใพใใAPIใฎๅ้ใชใฏใจในใๅถ้ใ่ถ ใใๅ ดๅใฏใไธ้ใๅผใไธใใๅฟ ่ฆใใใใพใ
-
ๅฎ้ใซใใฎใใใชๆฝ็ญใ้็จใใๅ ดๅใซใฏใๆฏๅ่กจ็คบๆณใฎ่ฆณ็นใใใๅฝใใๆฎๆฐใ0ใซใชใฃใๆ็นใง้ใใใซใญใฃใณใใผใณใ็ตไบใใฆใใ ใใใ
่จญๅฎๆ้
่จญๅฎใฎๆ้ ใฏๆฌกใฎ้ใใงใใ
- API v2 ใขใใชใไฝๆใใ
- API v2 ใขใใชใฎ ใขใฏใปในใใผใฏใณใ Craft Secret Manager ใซ็ป้ฒใใ
- Craft Functionsใฎใใกใณใฏใทใงใณใไฝๆใใ
- Craft Functionsใฎใจใณใใใคใณใใไฝๆใใ
- ใปใฐใกใณใใไฝๆใใ
- ๆฅๅฎขใตใผใในใไฝๆใใ ้ ็ชใซ่ฆใฆใฟใพใใใใ
1. API v2 ใขใใชใไฝๆใใ
KARTEใฎAPIใๅฉ็จใใใใใซใAPI v2ใขใใชใไฝๆใใพใใ
- ในใใข > API v2่จญๅฎ ใใใขใใชใๆฐ่ฆไฝๆ
- ใขใใชใฟใคใ ใ token ใซ่จญๅฎ
-
ๅฟ ่ฆใชscopeใ่ฟฝๅ
-
track.event.write
-
ใขใใชใไฟๅญใใไธๅบฆใ ใ่กจ็คบใใใใขใฏใปในใใผใฏใณใใกใขใใฆใใ
2. API v2 ใขใใชใฎ ใขใฏใปในใใผใฏใณใ Craft Secret Manager ใซ็ป้ฒใใ
API v2 ใขใใชใฎใขใฏใปในใใผใฏใณใCraft Functionsใใๅฎๅ จใซๅฉ็จใใใใใซใCraft Secret Manager ใซ็ป้ฒใใพใใ
- Craft > ใทใผใฏใฌใใ ใใใทใผใฏใฌใใใๆฐ่ฆไฝๆ
- ๅๅ ใซใใใใใใใๅๅใๅ ฅๅ
- ใกใขใใฆใใใAPI v2 ใขใใชใฎใขใฏใปในใใผใฏใณใ ใทใผใฏใฌใใใฎๅค ใซๅ ฅๅใใไฝๆ
- ใทใผใฏใฌใใๅใใกใขใใฆใใ
3. Craft Functionsใฎใใกใณใฏใทใงใณใไฝๆใใ
Craft Functionsใฎใใกใณใฏใทใงใณใไฝๆใใพใใไฝๆๆ้ ใฏๆฌกใฎ้ใใงใใ
-
Craft > ใใกใณใฏใทใงใณ > ๆฐ่ฆไฝๆ > ใใณใใฌใผใใใไฝๆ ใ้ธๆ
-
ใ Craft FunctionsใจCraft Counterใงๅฝใใไธ้ๆฐใฎใใใใๅผใๆฝ็ญใๅฎ่ฃ ใใ ใใจใใใใณใใฌใผใใๆค็ดขใๅๅพใใฟใณใใฏใชใใฏ
-
ๅๆ ใใฟใณใใฏใชใใฏ
-
ๅคๆฐ ใฟใใงๆฌกใฎๅคๆฐใฎๅคใ่จญๅฎใใ
-
PRIZES
-
ๅฝใใ็จฎๅฅใฎๅ็งฐใ่จญๅฎใใพใใใซใณใๅบๅใใง่คๆฐๆๅฎๅฏ่ฝใงใใ
-
ไพ: 1็ญ,2็ญ,3็ญ
-
LIMITS
-
ๅฝใใใฎไธ้ๆฐใ่จญๅฎใใพใใใซใณใๅบๅใใง่คๆฐๆๅฎๅฏ่ฝใงใPRIZESใจๅใ้ ็ชใงๅฏพๅฟใใไธ้ๆฐใ่จญๅฎใใพใใ
-
ไพ: 10,50,100
-
LOSE_PROBABILITY
-
ใใบใฌใฎ็ขบ็ใ่จญๅฎใใพใใ0ใใ1ใฎ้ใฎๅฐๆฐๅคใงๆๅฎใใพใใ
-
ไพ: 0.5
-
USER_PARTICIPATION_INTERVAL_MINUTES
-
ๅไธใฆใผใถใผใใใๅผใใซ้ฃ็ถใใฆๅๅ ใงใใชใๆ้ใๅๅไฝใง่จญๅฎใใพใใ0ใๆๅฎใใใจๅถ้ใชใใซใชใใพใใ
-
KARTE_APP_TOKEN_SECRET
-
ๆ้ 2ใงใกใขใใKARTE API v2ใขใใชใฎใขใฏใปในใใผใฏใณใฎใทใผใฏใฌใใๅใ่จญๅฎใใพใใ
-
ใใฎไปใฎๅคๆฐใฏใใฒใจใพใใใใฉใซใๅคใฎใพใพใงๅ้กใใใพใใ
-
ไฟๅญ ใใ
-
ใใใญใคๅฎไบๅพใ่จญๅฎ > ใใกใณใฏใทใงใณใฎๆๅนๅ ใซใใงใใฏใไปใใ
ๅฝใใๅคๅฎใฎใญใธใใฏใซใคใใฆ
ใใฎใใณใใฌใผใใซใใใๅฝใใ/ใฏใใใๅคๅฎใใใญใธใใฏใซใคใใฆ่ชฌๆใใพใใๅ่ณๅใฎๅฝใใ็ขบ็ใฏใๆฌกใฎใใใซ่จ็ฎใใใพใ๏ผ
- ใใฎ่ณๅใฎๅฝใใๆฎๆฐ / ๅ จไฝใฎๅฝใใๆฎๆฐ * (1 - ใฏใใ็ขบ็)
ๆฌกใฎใใใช็ถๆณใๅ ทไฝไพใจใใฆๆณๅฎใใพใ๏ผ
- PRIZES: 1็ญ,2็ญ,3็ญ
- LIMITS: 10,50,100
- LOSE_PROBABILITY: 0.5
ๅๆ็ถๆ ใงใฎ็ขบ็ใฏใๆฌกใฎ้ใใงใ๏ผ
-
ใฏใใใฎ็ขบ็: 0.5
-
ๅฝใใใฎ็ขบ็: 0.5
-
ๅ ใ1็ญใฎๅฝ้ธ็ขบ็: 10 / (10 + 50 + 100) * 0.5 โ 0.031 (็ด3.1%)
-
ๅ ใ2็ญใฎๅฝ้ธ็ขบ็: 50 / (10 + 50 + 100) * 0.5 โ 0.156 (็ด15.6%)
-
ๅ ใ3็ญใฎๅฝ้ธ็ขบ็: 100 / (10 + 50 + 100) * 0.5 โ 0.313 (็ด31.3%)
ใใจใใฐ1็ญใๆฎใ6ๅใ2็ญใๆฎใ15ๅใ3็ญใๆฎใ40ๅใซใชใฃใๅ ดๅใฎ็ขบ็ใฏๆฌกใฎ้ใใงใ๏ผ
-
ใฏใใใฎ็ขบ็: 0.5
-
ๅฝใใใฎ็ขบ็: 0.5
-
ๅ ใ1็ญใฎๅฝ้ธ็ขบ็: 6 / (6 + 15 + 40) * 0.5 โ 0.049 (็ด4.9%)
-
ๅ ใ2็ญใฎๅฝ้ธ็ขบ็: 15 / (6 + 15 + 40) * 0.5 โ 0.123 (็ด12.3%)
-
ๅ ใ3็ญใฎๅฝ้ธ็ขบ็: 40 / (6 + 15 + 40) * 0.5 โ 0.328 (็ด32.8%)
ใใใซใใใๅ็ใซๅๅฝใใใฎ็ขบ็ใๅคๅใใพใใ ๅฝใใๆฎๆฐใ็กใใชใฃใ่ณๅใฏ่ชๅใงๅฝใใ็ขบ็ใ0ใซใชใใใใๅฝใใใชใใชใใพใใ
ใชใใใใณใใฌใผใใฎใฝใผในใณใผใใฏGitHubใงๅ ฌ้ใใฆใใพใใ
craft-codes/craft-functions/lottery-with-limits-of-wins at main ยท plaidev/craft-codes
4. Craft Functionsใฎใจใณใใใคใณใใไฝๆใใ
ไฝๆใใใใกใณใฏใทใงใณใๅค้จใใๅฎ่กใงใใใใใซใใใใใฎใจใณใใใคใณใใไฝๆใใพใใ
- ไฝๆใใใใกใณใฏใทใงใณใฎ็ทจ้็ป้ขใใ ่จญๅฎ > ใจใณใใใคใณใ > ไฝๆ ใใฏใชใใฏ
- ่กจ็คบใใใใจใณใใใคใณใURLใใกใขใใฆใใ
5. ๆฅๅฎขใตใผใในใไฝๆใใ
ใใๅผใๆฉ่ฝใใฆใผใถใผใซๆไพใใใใใซใKARTEใฎๆฅๅฎขใขใฏใทใงใณใๅฉ็จใใฆใใใๅผใ็ป้ขใใใใใขใใๅฝขๅผใงไฝๆใใพใใ ใใฎใใใใขใใใฏใ่จญๅฎใใๆ้ๅ ใซใใๅผใใซๅๅ ใใฆใใชใใฆใผใถใผใซๅฏพใใฆ่กจ็คบใใใพใใ
ใใๅผใใขใฏใทใงใณใฎJavaScriptๅฎ่ฃ
ไปฅไธใฎJavaScriptใณใผใใฏใใฆใผใถใผใใใใใๅผใใใใฟใณใใฏใชใใฏใใ้ใซๅฎ่กใใใพใใ ใใฎใณใผใใฏใใใๅผใใฎใชใฏใจในใใ้ไฟกใใๅฝใใ/ใใบใฌใฎ็ตๆใซๅฟใใฆstateใๆดๆฐใใพใใ CRAFT_ENDPOINT_URLใฏๆ้ 4ใงใกใขใใใจใณใใใคใณใURLใซ็ฝฎใๆใใฆใใ ใใใ LOTTERY_KEYใฏใใๅผใๆฝ็ญๅๅฃซใๅบๅฅใใใใใฎ่ญๅฅๅญใงใใๅฝใใๆใฎใคใใณใ็ญใซๅซใพใใพใใ
var CRAFT_ENDPOINT_URL = “https://xxx.cev2.karte.io/functions/yyyyy";var LOTTERY_KEY = “lottery_key”;widget.setVal(“isLoading”, false);widget.method(“onClick”, function () { // Display loading indicator until the request is complete widget.setVal(“isLoading”, true); // Send the lottery request fetchData(function (item, error) { if (error) { console.error(error); widget.setState(3); // State for error: not winning } else { widget.setVal(“result”, item.result); // Change the state based on whether a prize was won if (item.result && item.result !== “No prize won”) { widget.setState(2); // State for winning } else { widget.setState(3); // State for not winning } } widget.setVal(“isLoading”, false); });});function fetchData(cb) { var payload = { userId: “#{user_id}”, lotteryKey: LOTTERY_KEY, }; fetch(CRAFT_ENDPOINT_URL, { method: “POST”, headers: { “Content-Type”: “application/json”, }, body: JSON.stringify(payload), }) .then(function (response) { return response.json(); }) .then(function (item) { cb(item); }) .catch(function (err) { cb(null, err); });}widget.show();
ใใๅผใใใใใขใใใฎๅฎ่ฃ
ใใๅผใใฎ็ตๆใซๅฟใใฆ่กจ็คบใใใๆฅๅฎขใตใผใในใฏไปฅไธใฎ้ใใงใใ ใฆใผใถใผใใใใใๅผใใใใฟใณใใฏใชใใฏใใใจใJavaScriptใCraft Functionsใธใชใฏใจในใใ้ไฟกใใ็ตๆใซๅฟใใฆๅฝใใใพใใฏใใบใฌใฎ็ป้ขใ่กจ็คบใใใพใใ
<div class=“karte-temp-whole”> <div class=“karte-temp-state1” krt-if=“state==1”> <i class=“karte-temp-close karte-close karte-temp-hover” krt-if=”#{close.use}"></i> <div class=“karte-temp-card”> <div class=“karte-temp-mainvisual”><img src="#{mainvisual}" alt="#{mainvisual_alt}" /></div> <div class=“karte-temp-wrap”> <div class=“karte-temp-title”>#{title}</div> <div class=“karte-temp-description”>#{description}</div> <a class=“karte-temp-btn karte-temp-hover” krt-on:click=“onClick”> <span krt-if="!isLoading">#{btn}</span> <div krt-else class=“drawing”> <i class=“loader” aria-hidden=“true”></i> #{loading_btn} </span> </a> </div> </div> </div> <div class=“karte-temp-state1” krt-if=“state==2”> <i class=“karte-temp-close karte-close karte-temp-hover” krt-if="#{close.use}"></i> <div class=“karte-temp-card”> <div class=“karte-temp-mainvisual”><img src="#{winvisual}" alt="#{winvisual_alt}" /></div> <div class=“karte-temp-wrap”> <div class=“karte-temp-title”>{{result}}#{win_title}</div> </div> </div> </div> <div class=“karte-temp-state1” krt-if=“state==3”> <i class=“karte-temp-close karte-close karte-temp-hover” krt-if="#{close.use}"></i> <div class=“karte-temp-card”> <div class=“karte-temp-mainvisual”><img src="#{losevisual}" alt="#{losevisual_alt}" /></div> <div class=“karte-temp-wrap”> <div class=“karte-temp-title”>#{lose_title}</div> </div> </div> </div></div>ๅฎ้ใซใฏๆฅๅฎขใตใผใในใ้ ไฟกใใใ็ถๆณใซๅใใใ้ ไฟก่จญๅฎใๅฎๆฝใใฆใใ ใใใ
ๅฎ้ใซๅใใใฆใฟใ
่จญๅฎใๅฎไบใใใใๅฎ้ใซๅไฝใ็ขบ่ชใใฆใฟใพใใใใ
ใพใใฏใใใใๅผใใใฟใณใๆผไธใใใจใใใใๅงใใพใใใใๅผใใๅงใพใใ็ตๆใ่กจ็คบใใใใใญใปในใไปฅไธใฎ็ปๅใง็ขบ่ชใงใใพใใ
ๆฌกใซใ่จญๅฎใๅคๆดใใฆใๅฝใใใฎไธ้ๆฐใ0ใซใใฆใฟใพใใใใใซใใใใในใฆใฎใฆใผใถใผใใใบใฌใซใชใใฏใใงใใ
ไธ่จใฎ่จญๅฎๅคๆดๅพใๅๅบฆใใใๅผใใใฟใณใๆผไธใใใจใไปฅไธใฎใใใซใใบใฌใๅบใใใจใ็ขบ่ชใงใใพใใ
ใใๅผใๆฉ่ฝใฎๅไฝ็ขบ่ชใ่กใใฆใ่จญๅฎใซๅฟใใ็ตๆใๅพใใใใใจใใใใใพใใใ
ใใๅผใใคใใณใใฎ้ไฟกใซใคใใฆ
ใใๅผใใใใใจใๅฝใใใใใบใฌใฎ็ตๆใซๅฟใใฆใคใใณใใFunctionsใใ้ไฟกใใใพใใ
- ๅฝใใใฎใคใใณใ:
- ใใบใฌใฎใคใใณใ:
ไพใใฐใ้็จไธใงๅฝใใใฆใผใถใผใฎไธ่ฆงใๆฝๅบใใใๅ ดๅใชใฉใๅฏพ่ฑก่ ใDatahubใฏใจใชใงๆฝๅบใใใใจใๅฏ่ฝใงใใ
ใใใใซ
ๆฌ่จไบใงใฏใCraft FunctionsใจCraft Counterใไฝฟใฃใฆใๅฝใใไธ้ๆฐใ่ๆ ฎใใใใๅผใๆฝ็ญใฎไฝใๆนใใ็ดนไปใใพใใใ
ไปๅใฎใฝใชใฅใผใทใงใณใงใฏๅฝใใ็ขบ็ใๅฝใใๆฎๆฐใซๅฟใใฆๅคๅใใใใใใไบๅฎใใฆใใๆฐใใๅฝใใๆฐใๅบใใฆใใพใฃใใใจใใไบๆ ใใ้็จใฎๆ้ใใใใใซ่ชๅใง้ฟใใใใจใใงใใพใใ
ใใฌใคใใงใฏใไธใฎไธญใซใคใณใใฏใใไธใใๆฐใใใฝใชใฅใผใทใงใณใไธ็ทใซใคใใไปฒ้ใๅ้ใใฆใใพใ๏ผใใฒๆฐ่ปฝใซใๅใๅใใใใ ใใใ
โ ใใผใใใผไผๆฅญใซใชใใใ
- CustomerData-Driven Solution ใไธ็ทใซๅตใใพใใใ๏ผ | PLAID Ecosystem
โ PLAIDใงๅใใใ
- Customer Engineer | ๅ้ใใธใทใงใณ | ๆ ชๅผไผ็คพใใฌใคใ
- Product Engineer | ๅ้ใใธใทใงใณ | ๆ ชๅผไผ็คพใใฌใคใ
Tags :- Craft Functions
- KARTE Web/App
Share :-
-
Craft Functions
-
KARTE Web/App
ใใฎSolutionใKARTE Craftใงๅฉ็จใใโปKARTE Craftใใพใ ๆๅนๅใใฆใใชใๅ ดๅใฏใใกใใใใๅใๅใใใใ ใใ๏ผ
FAQ
ใใฟใ ใใใจไผผใใใคใฏไฝใงใใ๏ผ
ใใ๏ผใใฟใใ๏ผใใฟใ ใใ๏ผๅฎใใ๏ผ็ฆๅผใ ใฎๅ ฑ้ใใๆๅณ ๅใๅฝขใฎๅคใใฎ็ดใๆจใชใฉใซใๆฐๅญใๆๅญ็ฌฆๅทใ่ชๅฅใชใฉใ่จใใใใใๅ่ชใซๅผใใใใใจ
ใใฟใ ใใใจไผผใใใคใฏไฝใงใใ๏ผ
ใใ๏ผใใฟใใ๏ผใใฟใ ใใ๏ผๅฎใใ๏ผ็ฆๅผใ ใฎๅ ฑ้ใใๆๅณ ๅใๅฝขใฎๅคใใฎ็ดใๆจใชใฉใซใๆฐๅญใๆๅญ็ฌฆๅทใ่ชๅฅใชใฉใ่จใใใใใๅ่ชใซๅผใใใใใจ
ใใณใดใซใผใฌใใใขใใชใฎใใใใใฏ๏ผ
ๆผใใใฎ่ชฐใ !? ใฏใใใฌใใงใใ่ฆใใใผใฟใฉใคใถใผ(ใโโใ ใจๆใไบบใในใคใใใชใณ!ใใฃใฆใขใณใฑใผใใงไฝฟใใใๆฉๆขฐ)ใๅ็พใใใขใใชใงใใ ใ
ๆฝ้ธใขใใชใจใฏไฝใงใใ๏ผ
ๅคงไบบๆฐใงใฎๅฝ็ชใใฐใซใผใๆฑบใใใใผใใฃใผใงใฎใใฌใผใณใไบคๆใใฏใใพใไปๆฅใฎ็ฎ็ซใชใฉใใใใจๆฑบใใใใใจใใใใจใใซไพฟๅฉใชในใใใฎใๆฝ้ธใขใใช
ใชใณใฉใคใณใซใธใใฎๅฐๅ
ฅใฏใซใผใฌใใใฒใผใ ใซใฉใฎใใใชๅฝฑ้ฟใไธใใพใใใ?
ใชใณใฉใคใณใซใธใใฎๅฐๅ ฅใฏใซใผใฌใใใฒใผใ ใซใฉใฎใใใชๅฝฑ้ฟใไธใใพใใใ? ใชใณใฉใคใณใซใธใใฎๅฐๅ ฅใฏใซใผใฌใใใฒใผใ ใซๅคงใใชๅฝฑ้ฟใไธใใพใใใใช
ๆฝ้ธใขใใชใจใฏไฝใงใใ๏ผ
ๅคงไบบๆฐใงใฎๅฝ็ชใใฐใซใผใๆฑบใใใใผใใฃใผใงใฎใใฌใผใณใไบคๆใใฏใใพใไปๆฅใฎ็ฎ็ซใชใฉใใใใจๆฑบใใใใใจใใใใจใใซไพฟๅฉใชในใใใฎใๆฝ้ธใขใใช
ๆฝ้ธใขใใชใจใฏไฝใงใใ๏ผ
ๅคงไบบๆฐใงใฎๅฝ็ชใใฐใซใผใๆฑบใใใใผใใฃใผใงใฎใใฌใผใณใไบคๆใใฏใใพใไปๆฅใฎ็ฎ็ซใชใฉใใใใจๆฑบใใใใใจใใใใจใใซไพฟๅฉใชในใใใฎใๆฝ้ธใขใใช
ๆ ็ปใๆๅญฆใชใฉใฎๅคง่กๆๅใซใใใฆใซใผใฌใใใฏใฉใฎใใใชๅฝนๅฒใๆใใใพใใใ?
ใซใผใฌใใใฏๆ ็ปใๆๅญฆใชใฉใฎๅคง่กๆๅใฎไธญใงใฉใฎใใใชๅฝนๅฒใๆใใใพใใใ? ใซใผใฌใใใฏๅคง่กๆๅใซใใใฆ้่ฆใชๅฝนๅฒใๆใใใฆใใใๆฐๅคใใฎๆ ็ป
ใใณใดใซใผใฌใใใขใใชใฎใใใใใฏ๏ผ
ๆผใใใฎ่ชฐใ !? ใฏใใใฌใใงใใ่ฆใใใผใฟใฉใคใถใผ(ใโโใ ใจๆใไบบใในใคใใใชใณ!ใใฃใฆใขใณใฑใผใใงไฝฟใใใๆฉๆขฐ)ใๅ็พใใใขใใชใงใใ ใ
ๅคงไบบๆฐใงใฎๅฝ็ชใใฐใซใผใๆฑบใใใใผใใฃใผใงใฎใใฌใผใณใไบคๆใใฏใใพใไปๆฅใฎ็ฎ็ซใชใฉใใใใจๆฑบใใใใใจใใใใจใใซไพฟๅฉใชในใใใฎใๆฝ้ธใขใใชใใใใๅผใใใซใผใฌใใใชใฉใๆฝ้ธใฎๆนๆณใฏใขใใชใซใใฃใฆใใพใใพใงใใ็ดฐใใชไปๆงใใขใใชใซใใฃใฆ็ฐใชใใฎใงใ็ตๅฑใฉใใใใใฎใใใใใซใใใงใใใญใใใใงไปๅใฏใๆฝ้ธใขใใชใฎใใใใไบบๆฐใฉใณใญใณใฐใจใใใฎ้ธใณๆนใใ็ดนไปใใพใใiPhoneใiPadใAndroidใงไฝฟ็จใงใใใขใใชใๅคๆฐใใใฏใขใใใใฆใใพใใฎใงใใใฒๅ่ใซใใฆใใ ใใใญ๏ผ็กๆใงไฝฟใใใใฎใใใใพใใ
ใใฎใตใคใใงใฏ้ข้ฃใใ่จไบใฎใฟใๅ้ใใฆใใพใใใชใชใธใใซใ่กจ็คบใใใซใฏใไปฅไธใฎใชใณใฏใใณใใผใใฆ้ใใฆใใ ใใใCraft FunctionsใจCraft Counterใงๅฝใใไธ้ๆฐใฎใใใใๅผใๆฝ็ญใๅฎ่ฃ ใใ