To run:
git clone [email protected]:richiepreece/adobe-livestream-demo
cd adobe-livestream-demo
cp example.config.json config.json
// Populate config file
npm install
npm start
This lab uses the following software: *Adobe Brackets *NodeJS *Mac OS Terminal
- Download the code.
- Go to the bookmarks in Chrome and select
https://github.com/richiepreece/adobe-livestream-demo
- Click the download green button
- Select “Download ZIP”
- Go to the bookmarks in Chrome and select
- Move the file and unzip it.
- Using Finder, locate the file in the Downloads folder.
- Move the file to your home directory.
- Unzip the file by double clicking it.
- Prepare the NodeJS app.
- Go to the terminal and navigate to the folder.
- Run “npm install” and wait.
- Copy the config file
cp example.config.json config.json
- Configure the app.
- Open the code in Brackets.
- Select the "File" (drop-down) -> "Open Folder".
- Select the folder of the app in your home directory.
- Update the config
- Open "config.json"
- Update the URL
- Update the username
- Update the password
- Update the ip
- Update the deskNum
- Open the code in Brackets.
- Run the app.
- To start the app, type this command in the terminal:
npm start
- To stop the app, push
control
+c
at the same time on the keyboard.
- Go to line 23 of
livestream_listener.js
. - Enter this block of code:
// Kill after after a certain # of hits.
if (hits == stopAfter) {
process.exit();
}
- Add the
stopAfter
variable on about line 14 with a value of1
;
var stopAfter = 1;
- Save
livestream_listener.js
. - Run the app in the terminal:
npm start
- To display the number of hits, we need a place in the app to do so when our processing is complete.
- Go to line 32 of
livestream_listener.js
. - Add this block of code:
var result = {
totalHits: hits,
recentHits: recentHits,
uniqueVisitors: _.keys(uniqueVisitors).length,
events: events,
props: props,
eVars: eVars,
desks: desks,
eventData: eventData.slice()
};
return result;
- Change the
stopAfter
value to10
on line 14. - Change the
console.log
on line 20 to give simple feedback when a hit is received.
console.log('hit');
- Save
livestream_listener.js
. - Go to
connector.js
line 36. - Add this block of code:
process.on("exit", function() {
write();
});
function write () {
_.each(callbacks.writeToDB, function (item) {
var result = item();
console.log(result); //TODO write to db
webserver.emit('results', result);
});
}
- Save
connector.js
. - Run the app in the terminal:
npm start
- Go to
livestream_listener.js
. - Change the
stopAfter
value to1000
on line 14. - On line 19, add:
// Increment total hit counter.
++recentHits;
- Go to line 45 and add this block under the
result
variable:
recentHits = 0;
- Save
livestream_listener.js
. - Go to
connector.js
. - Add this block of code on line 49:
setInterval(function () {
write();
}, 5000);
- Save
connector.js
. - Run the app in the terminal:
npm start
- To stop the app, push
control
+c
at the same time on the keyboard.
- Go to
livestream_listener.js
and add code for Unique Visitors on site at about line 21:
// Calculate Unique Visitors on site.
if(!uniqueVisitors[hit.visIdLow + '' + hit.visIdHigh]) {
uniqueVisitors[hit.visIdLow + '' + hit.visIdHigh] = true;
}
- Save
livestream_listener.js
. - Run the app in the terminal:
npm start
- Go to
livestream_listener.js
. - Add processing for Events, Props, and eVars by adding this block of code under the Unique Visitors section on line 26:
// All Events.
if(hit.events) {
_.each(hit.events, function (item, key) {
events[key] = events[key] ? events[key] + 1 : 1;
});
}
// All Props.
if(hit.props) {
_.each(hit.props, function (item, key) {
props[key] = props[key] ? props[key] + 1 : 1;
props[key] = props[key] || {};
props[key][item] = props[key][item] ? props[key][item] + 1 : 1;
});
}
// All eVars.
if(hit.evars && hit.evars.evars) {
_.each(hit.evars.evars, function (item, key) {
eVars[key] = eVars[key] || {};
eVars[key][item] = eVars[key][item] ? eVars[key][item] + 1 : 1;
});
}
- Save
livestream_listener.js
. - Run the app in the terminal:
npm start
- Go to
livestream_listener.js
. - Add processing for Single Events by adding this block of code under the All Evars section on line 50:
// Single Events
if(hit.events) {
_.each(hit.events, function (item, key) {
eventData.push({
eventName: key,
latitude: hit.geoLatitude,
longitude: hit.geoLongitude
});
});
}
- Add this line of code at line 85:
eventData.length = 0;
- Save
livestream_listener.js
. - Run the app in the terminal:
npm start