Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <section class="bcls-section">
<h2 id="inputs">Destinations Report</h2>

<fieldset class="bcls-fieldset"><legend>Basic Information</legend>

<p>By default, you will get results from the Brightcove Training Videos account.</p>

<p><span class="bcls-button" id="useMyAccount">Use My Account Instead</span></p>

<div id="basicInfo" style="display:none">
<table class="bcls-table">
	<tbody class="bcls-table__body">
		<tr>
			<td>Video Cloud Account (Publisher ID):</td>
			<td><input id="accountID" class="required aapi-request" type="text" size="55" /></td>
		</tr>
		<tr>
			<td class="align-top no-wrap">Client id:</td>
			<td><input id="client_id" class="required aapi-request" type="text" size="100" value="" />
			<p>&nbsp;</p>
			</td>
		</tr>
		<tr>
			<td class="align-top no-wrap">Client secret:</td>
			<td><input id="client_secret" class="required aapi-request" type="text" size="100" value="" />
			<p>&nbsp;</p>
			</td>
		</tr>
	</tbody>
</table>

<p class="small" id="n1"><sup class="red">[1]</sup> See <a href="/node/14056">Managing API Credentials</a> for information on getting client credentials.</p>

<h3>Current API request</h3>
<textarea id="requestURL" rows="3" cols="200"></textarea></div>

<p><button class="bcls-button" id="getData">Get Data for the Account</button></p>

<aside class="bcls-aside bcls-aside--information" id="gettingDataDisplay">Click Get Data for the Account when ready...</aside>
</fieldset>
</section>

<section class="bcls-section">
<h2 id="destinationResults">Destination URL report</h2>

<table class="bcls-table">
	<thead class="bcls-table__head">
		<tr>
			<th>URL</th>
			<th>Video Views</th>
		</tr>
	</thead>
	<tbody id="destinationReportTableBody">
	</tbody>
</table>
</section>

<section class="bcls-section">
<h2 id="destinationCSVsection">Destination URLs CSV</h2>

<p><textarea name="destinationCSV" id="destinationCSV" class="bcls-code"></textarea></p>
</section>

<section class="bcls-section">
<h2 id="playerDomainReport">Player domain report</h2>

<table class="bcls-table">
	<thead class="bcls-table__head">
		<tr>
			<th>Domain</th>
			<th>Player ID</th>
			<th>Player Name</th>
			<th>Video Views</th>
		</tr>
	</thead>
	<tbody id="playerReportTableBody">
	</tbody>
</table>
</section>

<section class="bcls-section">
<h2 id="playerCSVsection">Player domain CSV</h2>

<p><textarea name="destinationCVS" id="playerDomainCSV" class="bcls-code"></textarea></p>
</section>


              
            
!

CSS

              
                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #f5f5f5;
  font-family: sans-serif;
  margin: 2em;
}
/*
 * Styles essential to the sample
 * are below
 */
.bcls-code {
  color: #111;
  font-family: 'Source Code Pro',monospace;
  padding: 1em;
  width: 90%;
  min-height: 5em;
  background-color: #cfcfcf;
  font-size: 1rem;
}
.bcls-button {
  padding: .5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: .5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64AAB2;
  border: 1px #64AAB2 solid;
  border-radius: .5em;
}
a {
  color: RGB(118, 174, 181);
}
code {
  color: #E4B842;
  font-family: 'Source Code Pro',monospace;
}
              
            
!

JS

              
                var BCLS = (function(window, document) {
  var proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
    useMyAccount = document.getElementById('useMyAccount'),
    basicInfo = document.getElementById('basicInfo'),
    accountID = document.getElementById('accountID'),
    account_id = '1752604059001',
    clientId = document.getElementById('client_id'),
    clientSecret = document.getElementById('client_secret'),
    client_id = null,
    client_secret = null,
    videoSelector = document.getElementById('videoSelector'),
    destinationReportTableBody = document.getElementById('destinationReportTableBody'),
    destinationCSV = document.getElementById('destinationCSV'),
    playerReportTableBody = document.getElementById('playerReportTableBody'),
    playerDomainCSV = document.getElementById('playerDomainCSV'),
    getDataButton = document.getElementById('getData'),
    gettingDataDisplay = document.getElementById('gettingDataDisplay'),
    requestURL = document.getElementById('requestURL'),
    currentVideo,
    currentVideoObj,
    analyticsData = {},
    chartData = [],
    callType;

  // more robust test for strings 'not defined'
  /**
   * tests for all the ways a variable might be undefined or not have a value
   * @param {*} x the variable to test
   * @return {Boolean} true if variable is defined and has a value
   */
  function isDefined(x) {
    if (x === '' || x === null || x === undefined) {
      return false;
    }
    return true;
  }

  /**
   * Builds the API requests and handles responses
   * @param {String} type the request type (getCount | getVideos | getAnalytics)
   */
  function buildRequest(type) {
    var options = {},
      tmpArray,
      newVideoItem = {},
      videoItem,
      newEl,
      a,
      csvStr,
      txt,
      i,
      iMax,
      item,
      fields,
      frag;
    // add credentials if submitted
    if (isDefined(clientId.value) && isDefined(clientSecret.value)) {
      options.client_id = clientId.value;
      options.client_secret = clientSecret.value;
    }
    options.account_id = account_id;
    options.proxyURL = proxyURL;
    gettingDataDisplay.textContent = 'Getting data, please wait....';
    switch (type) {
      case 'getDesinations':
        options.url = 'https://analytics.api.brightcove.com/v1/data?accounts=' + account_id + '&dimensions=destination_domain,destination_path&limit=all&fields=destination_domain,destination_path,video_view&sort=destination_domain&from=alltime';
        requestURL.textContent = options.url;
        makeRequest(options, function(response) {
          response = JSON.parse(response);
          // create the video selector items from the response items
          frag = new DocumentFragment();
          csvStr = '"URL","Video Views"\n';
          iMax = response.items.length;
          for (i = 0; i < iMax; i++) {
            item = response.items[i];
            newEl = document.createElement('tr');
            frag.appendChild(newEl);
            newEl = document.createElement('td');
            frag.appendChild(newEl);
            a = document.createElement('a');
            newEl.appendChild(a);
            txt = document.createTextNode(item.destination_domain + item.destination_path);
            csvStr += '"//' + item.destination_domain + item.destination_path + '",';
            a.setAttribute('href', '//' + item.destination_domain + item.destination_path);
            a.appendChild(txt);
            newEl = document.createElement('td');
            txt = document.createTextNode(item.video_view);
            newEl.appendChild(txt);
            frag.appendChild(newEl);
            csvStr += '"' + item.video_view + '"\n';
          }
          // append the options to the video selector
          destinationReportTableBody.appendChild(frag);
          destinationCSV.textContent = csvStr;
          buildRequest('getPlayerDomains');
        });
        break;
      case 'getPlayerDomains':
        // fields to return
        fields = 'player,player_name,destination_domain,video_view,';
        options.url = 'https://analytics.api.brightcove.com/v1/data?accounts=' + account_id + '&dimensions=player,destination_domain&limit=all&fields=' + fields + '&sort=player';
        requestURL.textContent = options.url;
        makeRequest(options, function(response) {
          response = JSON.parse(response);
          // display the data
          frag = new DocumentFragment();
          csvStr = '"Domain","Player ID","Player Name","Video Views"\n';
          iMax = response.items.length;
          for (i = 0; i < iMax; i++) {
            item = response.items[i];
            newEl = document.createElement('tr');
            frag.appendChild(newEl);
            newEl = document.createElement('td');
            frag.appendChild(newEl);
            txt = document.createTextNode(item.destination_domain);
            csvStr += '"' + item.destination_domain + '",';
            newEl.appendChild(txt);
            frag.appendChild(newEl);
            newEl = document.createElement('td');
            frag.appendChild(newEl);
            txt = document.createTextNode(item.player);
            newEl.appendChild(txt);
            csvStr += '"' + item.player + '",';
            newEl = document.createElement('td');
            frag.appendChild(newEl);
            txt = document.createTextNode(item.player_name);
            newEl.appendChild(txt);
            csvStr += '"' + item.player_name + '",';
            newEl = document.createElement('td');
            frag.appendChild(newEl);
            txt = document.createTextNode(item.video_view);
            newEl.appendChild(txt);
            csvStr += '"' + item.video_view + '"\n';
          }
          playerReportTableBody.appendChild(frag);
          playerDomainCSV.textContent = csvStr;
        });
        gettingDataDisplay.textContent = 'Finished!';
        break;
    }
  }

  /**
   * send API request to the proxy
   * @param  {Object} options for the request
   * @param  {String} options.url the full API request URL
   * @param  {String="GET","POST","PATCH","PUT","DELETE"} requestData [options.requestType="GET"] HTTP type for the request
   * @param  {String} options.proxyURL proxyURL to send the request to
   * @param  {String} options.client_id client id for the account (default is in the proxy)
   * @param  {String} options.client_secret client secret for the account (default is in the proxy)
   * @param  {JSON} [options.requestBody] Data to be sent in the request body in the form of a JSON string
   * @param  {Function} [callback] callback function that will process the response
   */
  function makeRequest(options, callback) {
    var httpRequest = new XMLHttpRequest(),
      response,
      proxyURL = options.proxyURL,
      // response handler
      getResponse = function() {
        try {
          if (httpRequest.readyState === 4) {
            if (httpRequest.status >= 200 && httpRequest.status < 300) {
              response = httpRequest.responseText;
              // some API requests return '{null}' for empty responses - breaks JSON.parse
              if (response === '{null}') {
                response = null;
              }
              // return the response
              callback(response);
            } else {
              alert('There was a problem with the request. Request returned ' + httpRequest.status);
            }
          }
        } catch (e) {
          alert('Caught Exception: ' + e);
        }
      };
    /**
     * set up request data
     * the proxy used here takes the following request body:
     * JSON.stringify(options)
     */
    // set response handler
    httpRequest.onreadystatechange = getResponse;
    // open the request
    httpRequest.open('POST', proxyURL);
    // set headers if there is a set header line, remove it
    // open and send request
    httpRequest.send(JSON.stringify(options));
  }

  // set event listeners
  useMyAccount.addEventListener('click', function() {
    if (basicInfo.getAttribute('style') === 'display:none') {
      basicInfo.setAttribute('style', 'display:block');
      useMyAccount.textContent = 'Use Sample Account';
    } else {
      basicInfo.setAttribute('style', 'display:none');
      useMyAccount.textContent = 'Use My Account Instead';
    }

  });
  getDataButton.addEventListener('click', function() {
    account_id = (isDefined(accountID.value)) ? accountID.value : account_id;
    gettingDataDisplay.textContent = 'Getting video data...';
    buildRequest('getDesinations');
  });

  return {};
})(window, document);

              
            
!
999px

Console