| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticle.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticle.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticle.java
|
| index 9e8816656de283cdf913310e6bc11a4557cbc1e0..a2d81a1bdf3a5c9a277af5770f53d1abe4b73ab6 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticle.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetArticle.java
|
| @@ -6,6 +6,8 @@ package org.chromium.chrome.browser.ntp.snippets;
|
| import android.graphics.Bitmap;
|
|
|
| import org.chromium.base.metrics.RecordHistogram;
|
| +import org.chromium.base.metrics.RecordUserAction;
|
| +import org.chromium.chrome.browser.ntp.NewTabPageUma;
|
| import org.chromium.chrome.browser.ntp.cards.NewTabPageListItem;
|
|
|
| /**
|
| @@ -19,7 +21,7 @@ public class SnippetArticle implements NewTabPageListItem {
|
| public final String mUrl;
|
| public final String mAmpUrl;
|
| public final String mThumbnailUrl;
|
| - public final long mTimestamp;
|
| + public final long mPublishTimestampMilliseconds;
|
| public final float mScore;
|
| public final int mPosition;
|
|
|
| @@ -29,6 +31,9 @@ public class SnippetArticle implements NewTabPageListItem {
|
| /** Stores whether impression of this article has been tracked already. */
|
| private boolean mImpressionTracked;
|
|
|
| + /** Specifies ranges of positions for which we store position-specific sub-histograms. */
|
| + private static final int[] HISTOGRAM_FOR_POSITIONS = {0, 2, 4, 9};
|
| +
|
| /**
|
| * Creates a SnippetArticle object that will hold the data
|
| * @param title the title of the article
|
| @@ -50,7 +55,7 @@ public class SnippetArticle implements NewTabPageListItem {
|
| mUrl = url;
|
| mAmpUrl = ampUrl;
|
| mThumbnailUrl = thumbnailUrl;
|
| - mTimestamp = timestamp;
|
| + mPublishTimestampMilliseconds = timestamp;
|
| mScore = score;
|
| mPosition = position;
|
| }
|
| @@ -84,6 +89,30 @@ public class SnippetArticle implements NewTabPageListItem {
|
| mThumbnailBitmap = bitmap;
|
| }
|
|
|
| + /** Tracks click on this NTP snippet in UMA. */
|
| + public void trackClick() {
|
| + RecordUserAction.record("MobileNTP.Snippets.Click");
|
| + RecordHistogram.recordSparseSlowlyHistogram("NewTabPage.Snippets.CardClicked", mPosition);
|
| + NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_CLICKED);
|
| + NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_SNIPPET);
|
| +
|
| + // Track how the (approx.) position relates to age / score of the snippet that is clicked.
|
| + int ageInMinutes =
|
| + (int) ((System.currentTimeMillis() - mPublishTimestampMilliseconds) / 60000L);
|
| + recordAge("NewTabPage.Snippets.CardClickedAge", ageInMinutes);
|
| + recordScore("NewTabPage.Snippets.CardClickedScore", mScore);
|
| + int startPosition = 0;
|
| + for (int endPosition : HISTOGRAM_FOR_POSITIONS) {
|
| + if (mPosition >= startPosition && mPosition <= endPosition) {
|
| + String suffix = "_" + startPosition + "_" + endPosition;
|
| + recordAge("NewTabPage.Snippets.CardClickedAge" + suffix, ageInMinutes);
|
| + recordScore("NewTabPage.Snippets.CardClickedScore" + suffix, mScore);
|
| + break;
|
| + }
|
| + startPosition = endPosition + 1;
|
| + }
|
| + }
|
| +
|
| /** Tracks impression of this NTP snippet. */
|
| public void trackImpression() {
|
| // Track UMA only upon the first impression per life-time of this object.
|
| @@ -97,4 +126,18 @@ public class SnippetArticle implements NewTabPageListItem {
|
| public boolean impressionTracked() {
|
| return mImpressionTracked;
|
| }
|
| +
|
| + private static void recordAge(String histogramName, int ageInMinutes) {
|
| + // Negative values (when the time of the device is set inappropriately) provide no value.
|
| + if (ageInMinutes >= 0) {
|
| + // If the max value below (72 hours) were to be changed, the histogram should be renamed
|
| + // since it will change the shape of buckets.
|
| + RecordHistogram.recordCustomCountHistogram(histogramName, ageInMinutes, 1, 72 * 60, 50);
|
| + }
|
| + }
|
| +
|
| + private static void recordScore(String histogramName, float score) {
|
| + int recordedScore = Math.min((int) Math.ceil(score), 1000);
|
| + RecordHistogram.recordCount1000Histogram(histogramName, recordedScore);
|
| + }
|
| }
|
|
|