Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Demo/ParselyDemo/FirstViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class FirstViewController: UIViewController {

@IBAction func didTouchButton(_ sender: Any) {
os_log("didTouchButton", log: OSLog.default, type: .debug)
let demoMetas = ParselyMetadata(authors: ["Yogi Berr"])
let demoMetas = ParselyMetadata(authors: ["Yogi Berr"], page_type: "post")
delegate.parsely.trackPageView(url: "http://parsely.com/path/cool-blog-post/1?qsarg=nawp&anotherone=yup", metadata: demoMetas, extraData: ["product-id": "12345"], siteId: "subdomain.parsely-test.com")
}

Expand Down
9 changes: 8 additions & 1 deletion Sources/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class ParselyMetadata {
var section: String?
var tags: Array<String>?
var duration: TimeInterval?
var page_type: String?

/**
A class to manage and re-use metadata. Metadata contained in an instance of this
Expand All @@ -22,6 +23,7 @@ public class ParselyMetadata {
- Parameter section: Same as section for website integration.
- Parameter tags: Up to 20 tags on an event are allowed.
- Parameter duration: Durations passed explicitly to trackVideoStart take precedence over any in metadata.
- Parameter page_type: The type of page being tracked
*/
public init(canonical_url: String? = nil,
pub_date: Date? = nil,
Expand All @@ -30,7 +32,8 @@ public class ParselyMetadata {
image_url: String? = nil,
section: String? = nil,
tags: Array<String>? = nil,
duration: TimeInterval? = nil) {
duration: TimeInterval? = nil,
page_type: String? = nil) {
self.canonical_url = canonical_url
self.pub_date = pub_date
self.title = title
Expand All @@ -39,6 +42,7 @@ public class ParselyMetadata {
self.section = section
self.tags = tags
self.duration = duration
self.page_type = page_type
}

func toDict() -> Dictionary<String, Any> {
Expand Down Expand Up @@ -68,6 +72,9 @@ public class ParselyMetadata {
if let duration {
metas["duration"] = duration
}
if let page_type {
metas["page_type"] = page_type
}

return metas
}
Expand Down
15 changes: 12 additions & 3 deletions Tests/MetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class MetadataTests: XCTestCase {
"image_url": "http://parsely-test.com/image2",
"section": "Things my mother says",
"tags": ["tag1", "tag2"],
"duration": TimeInterval(100)
"duration": TimeInterval(100),
"page_type": "post"
]

func testToDictEmpty() {
Expand All @@ -37,7 +38,8 @@ class MetadataTests: XCTestCase {
image_url: expected["image_url"] as? String,
section: expected["section"] as? String,
tags: expected["tags"] as? Array<String>,
duration: expected["duration"] as? TimeInterval
duration: expected["duration"] as? TimeInterval,
page_type: expected["page_type"] as? String
)
let actual: Dictionary<String, Any> = metasUnderTest.toDict()
let pubDateUnix: String = String(format:"%i", (expected["pub_date"]! as! Date).millisecondsSince1970)
Expand Down Expand Up @@ -67,6 +69,9 @@ class MetadataTests: XCTestCase {
XCTAssertEqual(actual["duration"]! as! TimeInterval, expected["duration"]! as! TimeInterval,
"The duration field in the result of ParselyMetadata.toDict should match the duration argument " +
"used at initialization")
XCTAssertEqual(actual["page_type"]! as! String, expected["page_type"]! as! String,
"The page_type field in the result of ParselyMetadata.toDict should match the page_type argument " +
"used at initialization")
}

func testMetadata() {
Expand All @@ -78,7 +83,8 @@ class MetadataTests: XCTestCase {
image_url: expected["image_url"] as? String,
section: expected["section"] as? String,
tags: expected["tags"] as? Array<String>,
duration: expected["duration"] as? TimeInterval
duration: expected["duration"] as? TimeInterval,
page_type: expected["page_type"] as? String
)
XCTAssertEqual(metasUnderTest.canonical_url, expected["canonical_url"]! as? String,
"The canonical_url field on ParselyMetadata should match the canonical_url argument " +
Expand All @@ -104,5 +110,8 @@ class MetadataTests: XCTestCase {
XCTAssertEqual(metasUnderTest.duration, expected["duration"]! as? TimeInterval,
"The duration field on ParselyMetadata should match the duration argument " +
"used at initialization")
XCTAssertEqual(metasUnderTest.page_type, expected["page_type"]! as? String,
"The page_type field on ParselyMetadata should match the page_type argument " +
"used at initialization")
}
}
3 changes: 2 additions & 1 deletion Tests/RequestBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class RequestBuilderTests: XCTestCase {
image_url: "http://parsely-test.com/image2",
section: "Things my mother says",
tags: ["tag1", "tag2"],
duration: TimeInterval(100)
duration: TimeInterval(100),
page_type: "post"
)
return [Event(
"pageview",
Expand Down
6 changes: 4 additions & 2 deletions Tests/VideoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class VideoTests: ParselyTestCase {
image_url: nil,
section: testSectionFirst,
tags: nil,
duration: nil
duration: nil,
page_type: nil
)

videoManager.trackPlay(
Expand All @@ -104,7 +105,8 @@ class VideoTests: ParselyTestCase {
image_url: nil,
section: testSectionSecond,
tags: nil,
duration: nil
duration: nil,
page_type: nil
)

videoManager.trackPlay(
Expand Down