Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added start/stop content session

  • Loading branch information...
commit 22182ad7f8fcfff9bc9c8ee7a377936d06ff5d35 1 parent ceb5be5
Adam Mark adammark authored
Showing with 34 additions and 4 deletions.
  1. +1 −0  news-reader/README.md
  2. +33 −4 news-reader/javascripts/views/blog.js
1  news-reader/README.md
View
@@ -13,3 +13,4 @@ This template demonstrates how to make a simple news view from an
* Transitioning from one "page" to another with `bc.ui.forwardPage()`
and `bc.ui.backPage()`
* Cropping images with App Cloud image transcoding service
+* Starting and stopping a content session (for analytics)
37 news-reader/javascripts/views/blog.js
View
@@ -1,4 +1,6 @@
function BlogView() {
+ // current content session ID, for content analytics
+ var contentSessionId = null;
// initialize this view
this.init = function () {
@@ -26,14 +28,23 @@ function BlogView() {
var article = getArticle(guid);
renderArticleDetail(article);
+
+ startContentSession(article);
});
// listen for a "back" tap
$(".back-button").live("tap", function (evt) {
bc.ui.backPage();
+
+ endContentSession();
+ });
+
+ // listen for a viewfocus
+ $(bc).bind("viewfocus", function (evt) {
+ endContentSession();
});
- // recalculate scroll depth when images are loaded
+ // recalculate scroll depth whenever images are loaded
$(".page img").load(function (evt) {
bc.ui.refreshScrollers();
});
@@ -82,11 +93,9 @@ function BlogView() {
document.getElementById("article-detail").innerHTML = markup;
- // transition to the article
+ // transition to the detail "page"
var page = document.getElementById("detail-page");
-
bc.ui.forwardPage(page);
-
bc.ui.refreshScrollers();
};
@@ -113,6 +122,26 @@ function BlogView() {
return null;
};
+ // start content session
+ var startContentSession = function (article) {
+ contentSessionId = article.guid;
+
+ bc.metrics.startContentSession(contentSessionId, article.title);
+
+ console.log("Start content session: " + contentSessionId);
+ };
+
+ // end content session
+ var endContentSession = function () {
+ if (contentSessionId) {
+ bc.metrics.endContentSession(contentSessionId);
+
+ console.log("End content session: " + contentSessionId);
+ }
+
+ contentSessionId = null;
+ };
+
// show the "loading" message
var showLoadingMessage = function () {
document.getElementById("loading").style.opacity = 1;
Please sign in to comment.
Something went wrong with that request. Please try again.