Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
CB05E6C32D4954E400466376 /* Storefront.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storefront.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
6A4895F72E4E069C00D4AE90 /* Common */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Common; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
4EBBA7642A5F0CE200193E19 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
Expand Down Expand Up @@ -126,6 +130,7 @@
4EBBA77F2A5F0DA300193E19 /* Application */ = {
isa = PBXGroup;
children = (
6A4895F72E4E069C00D4AE90 /* Common */,
86250DE32AD5521C002E45C2 /* AppConfiguration.swift */,
4EBBA76A2A5F0CE200193E19 /* AppDelegate.swift */,
4EF54F232A6F456B00F5E407 /* CartManager.swift */,
Expand Down Expand Up @@ -214,6 +219,9 @@
);
dependencies = (
);
fileSystemSynchronizedGroups = (
6A4895F72E4E069C00D4AE90 /* Common */,
);
name = MobileBuyIntegration;
packageProductDependencies = (
4EBBA7A22A5F0F5600193E19 /* Buy */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,30 @@ public final class AppConfiguration: ObservableObject {
public var storefrontDomain: String = InfoDictionary.shared.domain

@Published public var universalLinks = UniversalLinks()

/// Prefill buyer information
@Published public var useVaultedState: Bool = false
@Published public var authenticated: Bool = false

/// Logger to retain Web Pixel events
let webPixelsLogger = FileLogger("analytics.txt")

// Configure ShopifyAcceleratedCheckouts
let acceleratedCheckoutsStorefrontConfig = ShopifyAcceleratedCheckouts.Configuration(
storefrontDomain: InfoDictionary.shared.domain,
storefrontAccessToken: InfoDictionary.shared.accessToken
)
var acceleratedCheckoutsStorefrontConfig: ShopifyAcceleratedCheckouts.Configuration {
return ShopifyAcceleratedCheckouts.Configuration(
storefrontDomain: InfoDictionary.shared.domain,
storefrontAccessToken: InfoDictionary.shared.accessToken,
customer: authenticated ? ShopifyAcceleratedCheckouts.Customer(
email: InfoDictionary.shared.email,
phoneNumber: InfoDictionary.shared.phone
) : nil
)
}

let acceleratedCheckoutsApplePayConfig = ShopifyAcceleratedCheckouts.ApplePayConfiguration(
merchantIdentifier: InfoDictionary.shared.merchantIdentifier,
contactFields: [.email]
)
var acceleratedCheckoutsApplePayConfig: ShopifyAcceleratedCheckouts.ApplePayConfiguration {
return ShopifyAcceleratedCheckouts.ApplePayConfiguration(
merchantIdentifier: InfoDictionary.shared.merchantIdentifier,
contactFields: authenticated ? [] : [.email, .phone]
)
}
}

public var appConfiguration = AppConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import Foundation
import ShopifyCheckoutSheetKit

class Analytics {
static func getUserId() -> String {
// return ID for user used in your existing analytics system
return "123"
}

static func record(_ event: PixelEvent) {
switch event {
case let .customEvent(customEvent):
if let genericEvent = AnalyticsEvent.from(customEvent, userId: getUserId()) {
Analytics.record(genericEvent)
}
case let .standardEvent(standardEvent):
Analytics.record(AnalyticsEvent.from(standardEvent, userId: getUserId()))
}
}

static func record(_ event: AnalyticsEvent) {
ShopifyCheckoutSheetKit.configuration.logger.log("[Web Pixel Event (\(event.type)] \(event.name)")
// send the event to an analytics system, e.g. via an analytics sdk
appConfiguration.webPixelsLogger.log(event.name)
}
}

// example type, e.g. that may be defined by an analytics sdk
struct AnalyticsEvent {
var type: PixelEvent
var name = ""
var userId = ""
var timestamp = ""
var checkoutTotal: Double? = 0.0

static func from(_ event: StandardEvent, userId: String) -> AnalyticsEvent {
return AnalyticsEvent(
type: .standardEvent(event),
name: event.name!,
userId: userId,
timestamp: event.timestamp!,
checkoutTotal: event.data?.checkout?.totalPrice?.amount ?? 0.0
)
}

static func from(_ event: CustomEvent, userId: String) -> AnalyticsEvent? {
guard event.name != nil else {
print("Failed to parse custom event", event)
return nil
}

return AnalyticsEvent(
type: .customEvent(event),
name: event.name!,
userId: userId,
timestamp: event.timestamp!,
checkoutTotal: nil
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import ShopifyAcceleratedCheckouts

/**
* Common event handlers that can be used across instances of AcceleratedCheckoutButtons()
*
* @example
* AcceleratedCheckoutButtons(cartID: cartId)
* .checkout(delegate: checkoutDelegate)
* .onError(AcceleratedCheckoutHandlers.handleError)
*/
enum AcceleratedCheckoutHandlers {
static func handleError(error: AcceleratedCheckoutError) {
print("[AcceleratedCheckoutHandlers] handleError: \(error)")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
MIT License

Copyright 2023 - Present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import Foundation
import ShopifyAcceleratedCheckouts
import ShopifyCheckoutSheetKit
import UIKit

/**
* Common CheckoutDelegate instance which can be reused across instances of Checkout Sheet Kit and Accelerated Checkouts.
*
* Use overrides to override the default behaviour.
*/
class CustomCheckoutDelegate: UIViewController, CheckoutDelegate {
func checkoutDidComplete(event _: CheckoutCompletedEvent) {
dismiss(animated: true)
}

func checkoutDidClickLink(url: URL) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}

func checkoutDidFail(error: ShopifyCheckoutSheetKit.CheckoutError) {
ShopifyCheckoutSheetKit.configuration.logger.log("Checkout failed: \(error.localizedDescription), Recoverable: \(error.isRecoverable)")
}

func checkoutDidEmitWebPixelEvent(event: ShopifyCheckoutSheetKit.PixelEvent) {
Analytics.record(event)
}

func checkoutDidCancel() {
dismiss(animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
},
"Handle Product URLs" : {

},
"If toggled on, customer information will be attached to cart from your app settings. When toggled off, customer information will be collected from the Apple Pay sheet." : {

},
"Loading products..." : {

Expand Down Expand Up @@ -114,6 +117,9 @@
},
"Universal Links" : {

},
"Use authenticated customer" : {

},
"Version" : {

Expand Down
Loading
Loading