Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Hackle JavaScript SDK 연동 및 기능 적용 예제</h1>
<div style="padding: 5px">
    <label for="uname">사용자 식별자를 입력하고 테스트 그룹 분배 버튼을 눌러주세요.</label><br><br>
    <input type="text" id="uname" name="uname">
    <input type="button" value="테스트 그룹 분배" onClick="FuncHackleSdk()">
</div>
<div style="padding: 5px" id="bgcolor">
  <p id="result"><i>분배 수행 후 여기에 분배 결과가 나타납니다.</i></p>
  <p id="reason"></p>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                /***************************************
  여러분의 워크스페이스로 테스트하려면
  SDK 키, 실험 키 값을 수정해야 합니다.
  이벤트 키는 수정하지 않아도 됩니다.
***************************************/
// SDK 키
HACKLE_SDK_KEY = "0wXYq7fkt1wnthsG5kmO2c3SKAI98PIh";
// 실험 키
const experimentKey = 9;
// 이벤트 키
const eventKey = "hackle_test_event_key";

/***************************************
  수정하지 마세요! - Hackle SDK 연동
***************************************/
!function(e,t){var n,a=3e3,c=!1,l=[];function r(){}r.prototype.onReady=function(e,t){var n={block:e,timeout:t};l.push(n)},r.prototype.setUserId=function(e){n=e},e.Hackle=e.Hackle||new r,e.hackleClient=e.hackleClient||new r;var o=setInterval(function(){if(c){clearInterval(o);for(var t=0;t<l.length;t++)
  e.hackleClient.onReady(l[t].block,l[t].timeout);l.length=0}(a-=50)<0&&clearInterval(o)},50),i=t.createElement("script");i.type="text/javascript",i.crossOrigin="anonymous",i.src="https://cdn.jsdelivr.net/npm/@hackler/js-client-sdk@2.0.0/lib/umd/hackle-js-client-sdk.min.js",
  i.async=!0;var s=t.getElementsByTagName("script")[0];s.parentNode.insertBefore(i,s),i.onload=function(){c=!0,e.Hackle=Hackle,n&&Hackle.setUserId(n),e.hackleClient=Hackle.createInstance(HACKLE_SDK_KEY)},i.onerror=function(){clearInterval(o)}}(window,document);

/********************************
  테스트 그룹 분배 버튼을 누를 때 호출
********************************/
function FuncHackleSdk() {
  // 입력된 사용자 식별자 가져오기
  var userId = document.getElementById("uname").value;
  
  // 사용자 식별자가 입력되지 않은 경우 경고
  if (userId == "") {
    alert("사용자 식별자를 입력해주세요.");
    return;
  }
  
  // SDK 전송을 위한 포맷으로 변경
  var user = { id: userId };
  
  /**************************
    SDK 기능 1. 테스트 그룹 분배
  **************************/
  const decision = hackleClient.variationDetail(experimentKey, user);
  const variation = decision.variation;
  const reason = decision.reason;
  
  // 분배 결과에 따라 다른 결과를 보여준다
  if (variation.toString() == "A") {
    // 테스트 그룹 A에 보여줄 화면 or 기능 or 로직
    document.getElementById("bgcolor").style.backgroundColor = "#FFCCFF";
    document.getElementById("result").innerHTML = userId + "의 테스트 그룹 분배 결과는 <b><font color=\"red\">대조군(테스트 그룹 A)</font></b>입니다.";
    document.getElementById("reason").innerText = "* 분배 사유: " + reason;
  }
  else if (variation.toString() == "B") {
    // 테스트 그룹 B에 보여줄 화면 or 기능 or 로직
    document.getElementById("bgcolor").style.backgroundColor = "#99CCFF";
    document.getElementById("result").innerHTML = userId + "의 테스트 그룹 분배 결과는 <b><font color=\"blue\">실험군(테스트 그룹 B)</font></b>입니다.";
    document.getElementById("reason").innerText = "* 분배 사유: " + reason;
  }
  else {
    // 테스트 그룹 분배 결과에 오류가 있을 경우
    document.getElementById("result").innerHTML = "테스트 그룹 분배 중 오류가 발생했습니다.";
  }
  
  /**********************************
     SDK 기능 2. 사용자 이벤트 전송
  **********************************/
  hackleClient.track(eventKey, user);
  alert("사용자 이벤트를 전송하였습니다.\neventKey = " + eventKey);
}

              
            
!
999px

Console