{
+ var connection: HttpURLConnection? = null
+ try {
+ connection = URL(url).openConnection() as HttpURLConnection
+ connection.doOutput = true
+ connection.setRequestProperty("Content-Type", "application/json")
+ val output = connection.outputStream
+ output.write(payload.toByteArray())
+ output.close()
+ connection.inputStream
+ } catch (ex: Exception) {
+ return Result.failure(ex)
+ } finally {
+ connection?.disconnect()
+ }
+
+ return Result.success(Unit)
+ }
+}
diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyCoroutineScope.kt b/parsely/src/main/java/com/parsely/parselyandroid/ParselyCoroutineScope.kt
new file mode 100644
index 00000000..1c7be0fe
--- /dev/null
+++ b/parsely/src/main/java/com/parsely/parselyandroid/ParselyCoroutineScope.kt
@@ -0,0 +1,9 @@
+package com.parsely.parselyandroid
+
+import kotlinx.coroutines.CoroutineName
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.SupervisorJob
+
+internal val sdkScope =
+ CoroutineScope(SupervisorJob() + Dispatchers.IO + CoroutineName("Parse.ly SDK Scope"))
diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyMetadata.java b/parsely/src/main/java/com/parsely/parselyandroid/ParselyMetadata.java
deleted file mode 100644
index 805902ab..00000000
--- a/parsely/src/main/java/com/parsely/parselyandroid/ParselyMetadata.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.parsely.parselyandroid;
-
-import androidx.annotation.Nullable;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Represents post metadata to be passed to Parsely tracking.
- *
- * This class is used to attach a metadata block to a Parse.ly pageview
- * request. Pageview metadata is only required for URLs not accessible over the
- * internet (i.e. app-only content) or if the customer is using an "in-pixel" integration.
- * Otherwise, metadata will be gathered by Parse.ly's crawling infrastructure.
- */
-public class ParselyMetadata {
- public ArrayList authors, tags;
- public String link, section, thumbUrl, title;
- public Calendar pubDate;
-
- /**
- * Create a new ParselyMetadata object.
- *
- * @param authors The names of the authors of the content. Up to 10 authors are accepted.
- * @param link A post's canonical url.
- * @param section The category or vertical to which this content belongs.
- * @param tags User-defined tags for the content. Up to 20 are allowed.
- * @param thumbUrl URL at which the main image for this content is located.
- * @param title The title of the content.
- * @param pubDate The date this piece of content was published.
- */
- public ParselyMetadata(
- @Nullable ArrayList authors,
- @Nullable String link,
- @Nullable String section,
- @Nullable ArrayList tags,
- @Nullable String thumbUrl,
- @Nullable String title,
- @Nullable Calendar pubDate
- ) {
- this.authors = authors;
- this.link = link;
- this.section = section;
- this.tags = tags;
- this.thumbUrl = thumbUrl;
- this.title = title;
- this.pubDate = pubDate;
- }
-
- /**
- * Turn this object into a Map
- *
- * @return a Map object representing the metadata.
- */
- public Map toMap() {
- Map output = new HashMap<>();
- if (this.authors != null) {
- output.put("authors", this.authors);
- }
- if (this.link != null) {
- output.put("link", this.link);
- }
- if (this.section != null) {
- output.put("section", this.section);
- }
- if (this.tags != null) {
- output.put("tags", this.tags);
- }
- if (this.thumbUrl != null) {
- output.put("thumb_url", this.thumbUrl);
- }
- if (this.title != null) {
- output.put("title", this.title);
- }
- if (this.pubDate != null) {
- output.put("pub_date_tmsp", this.pubDate.getTimeInMillis() / 1000);
- }
- return output;
- }
-}
-
diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyMetadata.kt b/parsely/src/main/java/com/parsely/parselyandroid/ParselyMetadata.kt
new file mode 100644
index 00000000..f7ad0d40
--- /dev/null
+++ b/parsely/src/main/java/com/parsely/parselyandroid/ParselyMetadata.kt
@@ -0,0 +1,69 @@
+package com.parsely.parselyandroid
+
+import java.util.Calendar
+
+/**
+ * Represents post metadata to be passed to Parsely tracking.
+ *
+ *
+ * This class is used to attach a metadata block to a Parse.ly pageview
+ * request. Pageview metadata is only required for URLs not accessible over the
+ * internet (i.e. app-only content) or if the customer is using an "in-pixel" integration.
+ * Otherwise, metadata will be gathered by Parse.ly's crawling infrastructure.
+ */
+open class ParselyMetadata
+/**
+ * Create a new ParselyMetadata object.
+ *
+ * @param authors The names of the authors of the content. Up to 10 authors are accepted.
+ * @param link A post's canonical url.
+ * @param section The category or vertical to which this content belongs.
+ * @param tags User-defined tags for the content. Up to 20 are allowed.
+ * @param thumbUrl URL at which the main image for this content is located.
+ * @param title The title of the content.
+ * @param pubDate The date this piece of content was published.
+ * @param pageType The type of page being tracked
+ */(
+ private val authors: List? = null,
+ @JvmField internal val link: String? = null,
+ private val section: String? = null,
+ private val tags: List? = null,
+ private val thumbUrl: String? = null,
+ private val title: String? = null,
+ private val pubDate: Calendar? = null,
+ private val pageType: String? = null
+) {
+ /**
+ * Turn this object into a Map
+ *
+ * @return a Map object representing the metadata.
+ */
+ open fun toMap(): Map {
+ val output: MutableMap = HashMap()
+ if (authors != null) {
+ output["authors"] = authors
+ }
+ if (link != null) {
+ output["link"] = link
+ }
+ if (section != null) {
+ output["section"] = section
+ }
+ if (tags != null) {
+ output["tags"] = tags
+ }
+ if (thumbUrl != null) {
+ output["thumb_url"] = thumbUrl
+ }
+ if (title != null) {
+ output["title"] = title
+ }
+ if (pubDate != null) {
+ output["pub_date_tmsp"] = pubDate.timeInMillis / 1000
+ }
+ if (pageType != null) {
+ output["page_type"] = pageType
+ }
+ return output
+ }
+}
diff --git a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java b/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java
index 8db1cdf0..17682e90 100644
--- a/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java
+++ b/parsely/src/main/java/com/parsely/parselyandroid/ParselyTracker.java
@@ -16,42 +16,22 @@
package com.parsely.parselyandroid;
+import static com.parsely.parselyandroid.Logging.log;
+
import android.content.Context;
-import android.content.SharedPreferences;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.os.AsyncTask;
-import android.provider.Settings.Secure;
+
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleEventObserver;
import androidx.lifecycle.ProcessLifecycleOwner;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.android.gms.ads.identifier.AdvertisingIdClient;
-import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
-import com.google.android.gms.common.GooglePlayServicesRepairableException;
-
-import java.io.EOFException;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Formatter;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.TimeZone;
-import java.util.Timer;
-import java.util.TimerTask;
import java.util.UUID;
+import kotlin.Unit;
+import kotlin.jvm.functions.Function0;
+
/**
* Tracks Parse.ly app views in Android apps
*
@@ -62,49 +42,59 @@ public class ParselyTracker {
private static ParselyTracker instance = null;
private static final int DEFAULT_FLUSH_INTERVAL_SECS = 60;
private static final int DEFAULT_ENGAGEMENT_INTERVAL_MILLIS = 10500;
- private static final int QUEUE_SIZE_LIMIT = 50;
- private static final int STORAGE_SIZE_LIMIT = 100;
- private static final String STORAGE_KEY = "parsely-events.ser";
-// emulator localhost
-// private static final String ROOT_URL = "http://10.0.2.2:5001/";
- private static final String ROOT_URL = "https://p1.parsely.com/";
- private static final String UUID_KEY = "parsely-uuid";
- private static final String VIDEO_START_ID_KEY = "vsid";
- private static final String PAGE_VIEW_ID_KEY = "pvid";
-
- protected ArrayList