Skip to content

Commit 3ae9382

Browse files
authored
Merge pull request #111 from Parsely/improve_javadoc
Improve code documentation
2 parents 458644c + 5742c39 commit 3ae9382

File tree

2 files changed

+58
-88
lines changed

2 files changed

+58
-88
lines changed

.github/workflows/generate-docs.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.kt

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@ import org.jetbrains.annotations.TestOnly
2121
/**
2222
* Tracks Parse.ly app views in Android apps
2323
*
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
2525
* flushes the queue to the Parse.ly pixel proxy server.
2626
*/
2727
public interface ParselyTracker {
2828

2929
/**
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.
3131
*
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
3534
* @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.
3938
* @param extraData A Map of additional information to send with the event.
4039
*/
4140
public fun trackPageview(
@@ -48,13 +47,18 @@ public interface ParselyTracker {
4847
/**
4948
* Start engaged time tracking for the given URL.
5049
*
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.
5153
*
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.
5556
*
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
5862
*/
5963
public fun startEngagement(
6064
url: String,
@@ -63,38 +67,36 @@ public interface ParselyTracker {
6367
)
6468

6569
/**
66-
* Stop engaged time tracking.
67-
*
68-
*
6970
* 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.
7375
*/
7476
public fun stopEngagement()
7577

7678
/**
7779
* Start video tracking.
7880
*
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.
8283
* Video metadata must be provided, specifically the video ID and video duration.
8384
*
84-
*
8585
* The `url` value is *not* the URL of a video, but the post which contains the video. If the video
8686
* 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
8888
* when crawled, but must but well-formatted so Parse.ly systems recognize it as belonging to
8989
* the customer.
9090
*
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+
*/
98100
public fun trackPlay(
99101
url: String,
100102
urlRef: String = "",
@@ -103,30 +105,23 @@ public interface ParselyTracker {
103105
)
104106

105107
/**
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.
107111
*
108112
*
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
115114
* like `onPause` or `onStop`. Otherwise, engaged time tracking may keep running in the background
116115
* and Parse.ly values may be inaccurate.
117116
*/
118117
public fun trackPause()
119118

120119
/**
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.
128123
*
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
130125
* like `onPause` or `onStop`. Otherwise, engaged time tracking may keep running in the background
131126
* and Parse.ly values may be inaccurate.
132127
*/
@@ -143,13 +138,16 @@ public interface ParselyTracker {
143138
}
144139

145140
/**
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.
147143
*
148-
* @param siteId The Parsely public site id (eg "example.com")
144+
*
145+
* @param siteId The Parsely public site id (eg "example.com")
149146
* @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.
153151
*/
154152
@JvmStatic
155153
@JvmOverloads
@@ -165,6 +163,15 @@ public interface ParselyTracker {
165163
instance = ParselyTrackerInternal(siteId, flushInterval, context, dryRun)
166164
}
167165

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+
*/
168175
@JvmStatic
169176
public fun sharedInstance(): ParselyTracker = ensureInitialized()
170177

0 commit comments

Comments
 (0)