@@ -21,21 +21,20 @@ import org.jetbrains.annotations.TestOnly
21
21
/* *
22
22
* Tracks Parse.ly app views in Android apps
23
23
*
24
- * Accessed as a singleton. Maintains a queue of pageview events in memory and periodically
24
+ * Accessed as a singleton. Maintains a queue of events in memory and periodically
25
25
* flushes the queue to the Parse.ly pixel proxy server.
26
26
*/
27
27
public interface ParselyTracker {
28
28
29
29
/* *
30
- * Register a pageview event using a URL and optional metadata.
30
+ * Register a pageview event using a URL and optional metadata. You should only call this method once per page view.
31
31
*
32
- * @param url The URL of the article being tracked
33
- * (eg: "http://example.com/some-old/article.html")
34
- * @param urlRef Referrer URL associated with this video view.
32
+ * @param url The URL of the article being tracked (eg: "http://example.com/some-old/article.html")
33
+ * @param urlRef The url of the page that linked to the viewed page. Analogous to HTTP referer
35
34
* @param urlMetadata Optional metadata for the URL -- not used in most cases. Only needed
36
- * when `url` isn't accessible over the Internet (i.e. app-only
37
- * content). Do not use this for **content also hosted on** URLs Parse.ly
38
- * would normally crawl.
35
+ * when `url` isn't accessible over the Internet (i.e. app-only
36
+ * content). Do not use this for **content also hosted on** URLs Parse.ly
37
+ * would normally crawl.
39
38
* @param extraData A Map of additional information to send with the event.
40
39
*/
41
40
public fun trackPageview (
@@ -48,13 +47,18 @@ public interface ParselyTracker {
48
47
/* *
49
48
* Start engaged time tracking for the given URL.
50
49
*
50
+ * Start engaged time tracking for the given URL. Once called, the Parse.ly tracking script
51
+ * will automatically send `heartbeat` events periodically to capture engaged time for this url
52
+ * until engaged time tracking stops.
51
53
*
52
- * This starts a timer which will send events to Parse.ly on a regular basis
53
- * to capture engaged time for this URL. The value of `url` should be a URL for
54
- * which `trackPageview` has been called.
54
+ * This call also automatically stops tracking engaged time for any urls that are not
55
+ * the current url.
55
56
*
56
- * @param url The URL to track engaged time for.
57
- * @param urlRef Referrer URL associated with this video view.
57
+ * The value of `url` should be a URL for which [trackPageview] has been called.
58
+ *
59
+ * @param url The URL of the tracked article (eg: “http://example.com/some-old/article.html“)
60
+ * @param urlRef The url of the page that linked to the page being engaged with. Analogous to HTTP referer
61
+ * @param extraData A map of additional information to send with the generated `heartbeat` events
58
62
*/
59
63
public fun startEngagement (
60
64
url : String ,
@@ -63,38 +67,36 @@ public interface ParselyTracker {
63
67
)
64
68
65
69
/* *
66
- * Stop engaged time tracking.
67
- *
68
- *
69
70
* Stops the engaged time tracker, sending any accumulated engaged time to Parse.ly.
70
- * NOTE: This **must** be called in your `MainActivity` during various Android lifecycle events
71
- * like `onPause` or `onStop`. Otherwise, engaged time tracking may keep running in the background
72
- * and Parse.ly values may be inaccurate.
71
+ *
72
+ * NOTE: This **must** be called during various Android lifecycle events like
73
+ * `onPause` or `onStop`. Otherwise, engaged time tracking may keep running
74
+ * in the background and Parse.ly values may be inaccurate.
73
75
*/
74
76
public fun stopEngagement ()
75
77
76
78
/* *
77
79
* Start video tracking.
78
80
*
79
- *
80
- * Starts tracking view time for a video being viewed at a given url. Will send a `videostart`
81
- * event unless the same url/videoId had previously been paused.
81
+ * This starts tracking view time for a video that someone is watching at a given url.
82
+ * It will send a `videostart` event unless the same url/videoId had previously been paused.
82
83
* Video metadata must be provided, specifically the video ID and video duration.
83
84
*
84
- *
85
85
* The `url` value is *not* the URL of a video, but the post which contains the video. If the video
86
86
* is not embedded in a post, then this should contain a well-formatted URL on the customer's
87
- * domain (e.g. http://<CUSTOMERDOMAIN> /app-videos). This URL doesn't need to return a 200 status
87
+ * domain (e.g. http://example.com /app-videos). This URL doesn't need to return a 200 status
88
88
* when crawled, but must but well-formatted so Parse.ly systems recognize it as belonging to
89
89
* the customer.
90
90
*
91
- * @param url URL of post the video is embedded in. If videos is not embedded, a
92
- * valid URL for the customer should still be provided.
93
- * (e.g. http://<CUSTOMERDOMAIN>/app-videos)
94
- * @param urlRef Referrer URL associated with this video view.
95
- * @param videoMetadata Metadata about the video being tracked.
96
- * @param extraData A Map of additional information to send with the event.
97
- </CUSTOMERDOMAIN></CUSTOMERDOMAIN> */
91
+ * If a video is already being tracked when this method is called, unless it's the same video,
92
+ * the existing video tracking will be stopped and a new `videostart` event will be sent for the new video.
93
+ *
94
+ * @param url URL of post with the embedded video. If you haven’t embedded the video,
95
+ * then send a valid URL matching your domain. (e.g. http://example.com/app-videos)
96
+ * @param urlRef The url of the page that linked to the page being engaged with. Analogous to HTTP referer
97
+ * @param videoMetadata Metadata about the tracked video
98
+ * @param extraData A Map of additional information to send with the event
99
+ */
98
100
public fun trackPlay (
99
101
url : String ,
100
102
urlRef : String = "",
@@ -103,30 +105,23 @@ public interface ParselyTracker {
103
105
)
104
106
105
107
/* *
106
- * Pause video tracking.
108
+ * Pause video tracking for an ongoing video. If [trackPlay] is immediately called again
109
+ * for the same video, a new `videostart` event will not be sent. This models a user pausing
110
+ * a playing video.
107
111
*
108
112
*
109
- * Pauses video tracking for an ongoing video. If [.trackPlay] is immediately called again for
110
- * the same video, a new video start event will not be sent. This models a user pausing a
111
- * playing video.
112
- *
113
- *
114
- * NOTE: This or [.resetVideo] **must** be called in your `MainActivity` during various Android lifecycle events
113
+ * NOTE: This or [resetVideo] **must** be called during various Android lifecycle events
115
114
* like `onPause` or `onStop`. Otherwise, engaged time tracking may keep running in the background
116
115
* and Parse.ly values may be inaccurate.
117
116
*/
118
117
public fun trackPause ()
119
118
120
119
/* *
121
- * Reset tracking on a video.
122
- *
123
- *
124
- * Stops video tracking and resets internal state for the video. If [.trackPlay] is immediately
125
- * called for the same video, a new video start event is set. This models a user stopping a
126
- * video and (on [.trackPlay] being called again) starting it over.
127
- *
120
+ * Stops video tracking and resets internal state for the video.
121
+ * If [trackPlay] is immediately called for the same video, a new `videostart` event is set.
122
+ * This models a user stopping a video and (on [trackPlay] being called again) starting it over.
128
123
*
129
- * NOTE: This or [. trackPause] **must** be called in your `MainActivity` during various Android lifecycle events
124
+ * NOTE: This or [trackPause] **must** be called during various Android lifecycle events
130
125
* like `onPause` or `onStop`. Otherwise, engaged time tracking may keep running in the background
131
126
* and Parse.ly values may be inaccurate.
132
127
*/
@@ -143,13 +138,16 @@ public interface ParselyTracker {
143
138
}
144
139
145
140
/* *
146
- * Singleton instance factory Note: this must be called before [.sharedInstance]
141
+ * Singleton instance factory. This **must** be called before [sharedInstance]
142
+ * If this method is called when an instance already exists, a [ParselyAlreadyInitializedException] will be thrown.
147
143
*
148
- * @param siteId The Parsely public site id (eg "example.com")
144
+ *
145
+ * @param siteId The Parsely public site id (eg "example.com")
149
146
* @param flushInterval The interval at which the events queue should flush, in seconds
150
- * @param context The current Android application context
151
- * @param dryRun If set to `true`, events **won't** be sent to Parse.ly server
152
- * @return The singleton instance
147
+ * @param context The current Android application context
148
+ * @param dryRun If set to `true`, events **won't** be sent to Parse.ly server
149
+ * @return The singleton instance
150
+ * @throws ParselyAlreadyInitializedException if the ParselyTracker instance is already initialized.
153
151
*/
154
152
@JvmStatic
155
153
@JvmOverloads
@@ -165,6 +163,15 @@ public interface ParselyTracker {
165
163
instance = ParselyTrackerInternal (siteId, flushInterval, context, dryRun)
166
164
}
167
165
166
+ /* *
167
+ * Returns the singleton instance of the ParselyTracker.
168
+ *
169
+ * This method **must** be called after the [init] method.
170
+ * If the [init] method hasn't been called before this method, a [ParselyNotInitializedException] will be thrown.
171
+ *
172
+ * @return The singleton instance of ParselyTracker.
173
+ * @throws ParselyNotInitializedException if the ParselyTracker instance is not initialized.
174
+ */
168
175
@JvmStatic
169
176
public fun sharedInstance (): ParselyTracker = ensureInitialized()
170
177
0 commit comments