-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
2,243 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule Examples
updated
4 files
+104 −22 | demo/CommonSwiftCode/DemoUtils.swift | |
+3 −0 | demo/CommonSwiftCode/PageViewController.swift | |
+3 −3 | demo/SnowplowObjcDemo/Podfile.lock | |
+3 −3 | demo/SnowplowSwiftCocoapodsDemo/Podfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
class EcommerceControllerImpl: Controller, EcommerceController { | ||
|
||
func setEcommerceScreen(_ screen: EcommerceScreenEntity) { | ||
let plugin = PluginConfiguration(identifier: "ecommercePageTypePluginInternal") | ||
_ = plugin.entities { _ in [screen.entity] } | ||
serviceProvider.addPlugin(plugin: plugin) | ||
} | ||
|
||
func setEcommerceUser(_ user: EcommerceUserEntity) { | ||
let plugin = PluginConfiguration(identifier: "ecommerceUserPluginInternal") | ||
_ = plugin.entities { _ in [user.entity] } | ||
serviceProvider.addPlugin(plugin: plugin) | ||
} | ||
|
||
func removeEcommerceScreen() { | ||
serviceProvider.removePlugin(identifier: "ecommercePageTypePluginInternal") | ||
} | ||
|
||
func removeEcommerceUser() { | ||
serviceProvider.removePlugin(identifier: "ecommerceUserPluginInternal") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
/** | ||
Controller for managing Ecommerce entities. | ||
*/ | ||
@objc(SPEcommController) | ||
public protocol EcommerceController { | ||
|
||
/// Add an ecommerce Screen/Page entity to all subsequent events. | ||
/// - Parameter screen: A EcommScreenEntity. | ||
@objc | ||
func setEcommerceScreen(_ screen: EcommerceScreenEntity) | ||
|
||
/// Add an ecommerce User entity to all subsequent events. | ||
/// - Parameter user: A EcommUserEntity. | ||
@objc | ||
func setEcommerceUser(_ user: EcommerceUserEntity) | ||
|
||
/// Stop adding a Screen/Page entity to events. | ||
@objc | ||
func removeEcommerceScreen() | ||
|
||
/// Stop adding a User entity to events. | ||
@objc | ||
func removeEcommerceUser() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
/** | ||
Provided to certain Ecommerce events. The Cart properties will be sent with the event as a Cart entity. | ||
Entity schema: `iglu:com.snowplowanalytics.snowplow.ecommerce/cart/jsonschema/1-0-0` | ||
*/ | ||
@objc(SPCartEntity) | ||
public class CartEntity: NSObject { | ||
/// The total value of the cart after this interaction. | ||
@objc | ||
public var totalValue: Decimal | ||
|
||
/// The currency used for this cart (ISO 4217). | ||
@objc | ||
public var currency: String | ||
|
||
/// The unique ID representing this cart. | ||
@objc | ||
public var cartId: String? | ||
|
||
internal var entity: SelfDescribingJson { | ||
var data: [String : Any] = [ | ||
"total_value": totalValue, | ||
"currency": currency | ||
] | ||
if let cartId = cartId { data["cart_id"] = cartId } | ||
|
||
return SelfDescribingJson(schema: ecommerceCartSchema, andData: data) | ||
} | ||
|
||
/// - Parameter totalValue: The total value of the cart after this interaction. | ||
/// - Parameter currency: The currency used for this cart (ISO 4217). | ||
/// - Parameter cartId: The unique ID representing this cart. | ||
@objc | ||
public init( | ||
totalValue: Decimal, | ||
currency: String, | ||
cartId: String? = nil) { | ||
self.totalValue = totalValue | ||
self.currency = currency | ||
self.cartId = cartId | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
Sources/Snowplow/Ecommerce/Entities/EcommerceScreenEntity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
/** | ||
Attach Ecommerce Screen (Page) details to events. It is designed to help with grouping insights by | ||
screen/page type, e.g. Product description, Product list, Home. | ||
Entity schema: `iglu:com.snowplowanalytics.snowplow.ecommerce/page/jsonschema/1-0-0` | ||
*/ | ||
@objc(SPEcommerceScreenEntity) | ||
public class EcommerceScreenEntity: NSObject { | ||
/// The type of screen that was visited, e.g. homepage, product details, cart, checkout, etc. | ||
@objc | ||
public var type: String | ||
|
||
/// The language that the screen is based in. | ||
@objc | ||
public var language: String? | ||
|
||
/// The locale version of the app that is running. | ||
@objc | ||
public var locale: String? | ||
|
||
internal var entity: SelfDescribingJson { | ||
var data: [String : Any] = ["type": type] | ||
if let language = language { data["language"] = language } | ||
if let locale = locale { data["locale"] = locale } | ||
|
||
return SelfDescribingJson(schema: ecommercePageSchema, andData: data) | ||
} | ||
|
||
/// - Parameter type: The type of screen that was visited, e.g. homepage, product details, cart, checkout, etc. | ||
/// - Parameter language: The language that the screen is based in. | ||
/// - Parameter locale: The locale version of the app that is running. | ||
@objc | ||
public init( | ||
type: String, | ||
language: String? = nil, | ||
locale: String? = nil | ||
) { | ||
self.type = type | ||
self.language = language | ||
self.locale = locale | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
Sources/Snowplow/Ecommerce/Entities/EcommerceUserEntity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) 2013-2023 Snowplow Analytics Ltd. All rights reserved. | ||
// | ||
// This program is licensed to you under the Apache License Version 2.0, | ||
// and you may not use this file except in compliance with the Apache License | ||
// Version 2.0. You may obtain a copy of the Apache License Version 2.0 at | ||
// http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the Apache License Version 2.0 is distributed on | ||
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
// express or implied. See the Apache License Version 2.0 for the specific | ||
// language governing permissions and limitations there under. | ||
|
||
import Foundation | ||
|
||
/** | ||
Attach Ecommerce User details to events. It is designed to help in modeling guest/non-guest account activity. | ||
Entity schema: `iglu:com.snowplowanalytics.snowplow.ecommerce/user/jsonschema/1-0-0` | ||
*/ | ||
@objc(SPEcommerceUserEntity) | ||
public class EcommerceUserEntity: NSObject { | ||
/// The user ID. | ||
@objc | ||
public var id: String | ||
|
||
/// Whether or not the user is a guest. | ||
public var isGuest: Bool? | ||
|
||
/// The user's email address. | ||
@objc | ||
public var email: String? | ||
|
||
internal var entity: SelfDescribingJson { | ||
var data: [String : Any] = ["id": id] | ||
if let isGuest = isGuest { data["is_guest"] = isGuest } | ||
if let email = email { data["email"] = email } | ||
|
||
return SelfDescribingJson(schema: ecommerceUserSchema, andData: data) | ||
} | ||
|
||
/// - Parameter id: The user ID. | ||
/// - Parameter isGuest: Whether or not the user is a guest. | ||
/// - Parameter email: The user's email address. | ||
public init( | ||
id: String, | ||
isGuest: Bool? = nil, | ||
email: String? = nil | ||
) { | ||
self.id = id | ||
self.isGuest = isGuest | ||
self.email = email | ||
} | ||
|
||
/// - Parameter id: The user ID. | ||
/// - Parameter email: The user's email address. | ||
@objc | ||
public init( | ||
id: String, | ||
email: String? = nil | ||
) { | ||
self.id = id | ||
self.email = email | ||
} | ||
|
||
/// Whether or not the user is a guest. | ||
@objc | ||
public func isGuest(_ isGuest: Bool) -> Self { | ||
self.isGuest = isGuest | ||
return self | ||
} | ||
} |
Oops, something went wrong.