- Download the tech lab
- Introduce the basic HTML structure of our page
- Make a basic request from the page
- Do something with the response that we get
We will use GitHub to distribute this material to the lab workstations.
- Open Google Chrome and browse to
http://git.io/realtimelab
- Click the button labeled "Clone or Download", then "Download ZIP" to download the zip package
- Locate the zip file and expand the package
- Open the application "Brackets" from the application menu. We'll use this application to work from
- Click File > Open Folder
- Find the folder which you expanded in the previous steps. It should be in your downloads folder.
- Open up the
index.html
in that folder (index.html
). This is what we will be using to create our dashboard page.
Before we starting editing the file, we want to take a quick look at the JavaScript libraries used to help create this example.
-
js/jquery-2.2.3.min.js
is a common JavaScript library used by the other libraries. We are also using thejs/jquery-animateNumber/jquery.animateNumber.min.js
andjs/jquery.basic_table.js
JQuery plugins for data display.<script src="js/jquery-2.2.3.min.js" type="text/javascript"></script> <script src="js/jquery-animateNumber/jquery.animateNumber.min.js" type="text/javascript"></script> <script src="js/jquery.basic_table.js" type="text/javascript"></script>
-
js/d3.v2.js
is a charting library we will use to make graphs.<script src="js/d3.v2.js" type="text/javascript" ></script> <script src="js/d3.animated_trend.js" type="text/javascript"></script>
-
js/marketing-cloud-javascript-sdk/marketing_cloud.js
is another Adobe library that simplifies interaction with the Analytics API.js/wsse.js
is also an Adobe library that handles the auththenication with the Analytics API. The source for these libraries can be found here. The credentials used in this example are stored in theconfig.js
file and are the same we used during lesson 1 with the API explorer.<script src="js/marketing-cloud-javascript-sdk/marketing_cloud.js" type="text/javascript"></script> <script src="js/marketing-cloud-javascript-sdk/wsse.js" type="text/javascript"></script> <script src="js/config.js" type="text/javascript"></script>
-
js/custom.js
is a library we created for this example that has some convenience methods for working with strings and arrays.<script src="js/custom.js" type="text/javascript"></script>
-
js/real_time_report.js
is another library written for this example that encapsulates formatting and display logic for the Real-time report response data.<script src="js/real_time_report.js" type="text/javascript"></script>
We will use JavaScript on the page to request a Real-time report and display the raw result.
- Click File > Live Preview. This will execute the page as it currently stands. You will see a list of report suites. These are retrieved from the Analytics API using the Company.GetReportSuites API call. We want to remove this API call and replace it with a call to get a Real-time report.
-
Remove the
MarketingCloud.makeRequest
code block which callsCompany.GetReportSuites
(near line 25):////////////////////////////////// // COMPANY.GETREPORTSUITES EXAMPLE ////////////////////////////////// MarketingCloud.makeRequest(config.username, config.secret, 'Company.GetReportSuites', {}, config.endpoint, function(response) { $('#dashboard').html(JSON.stringify(response.responseJSON)); });
-
Enable the
BASIC REPORT.RUN REQUEST
call by removing the block comments (e.g./*
and*/
) surrounding it://///////////////////////// // BASIC REPORT.RUN REQUEST /////////////////////////// MarketingCloud.makeRequest(config.username, config.secret, 'Report.Run', { "reportDescription": { "source": "realtime", "reportSuiteID": "rtd-example", "metrics": [ { "id": "instances" } ], "elements": [ { "id": "page" } ], "dateGranularity": "minute:1", "dateFrom": "-15 minutes" } }, config.endpoint, function(response) { $('#dashboard').html(JSON.stringify(response.responseJSON)); });
-
Click File > Live Preview and you should see the raw result of the Real-time report in much the same format as we saw when using the API explorer.
Continue to Lesson 3 »