Skip to content

Commit

Permalink
Merge pull request #52 from visenze/feature/multiple-instance
Browse files Browse the repository at this point in the history
[ES-7453] instruction on creating multiple placements, allow access to client for configuration
  • Loading branch information
thehung111 authored May 5, 2023
2 parents 7d3cdee + ee79086 commit afbcc67
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
54 changes: 41 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [3. Initialization](#3-initialization)
- [3.1 ViSearch](#31-visearch)
- [3.2 ProductSearch](#32-productsearch)
- [3.2.1 Setup for multiple placements](#321-setup-for-multiple-placements)
- [4. Solution APIs](#4-solution-apis)
- [4.1 ViSearch](#41-visearch)
- [4.1.1 Visually Similar Recommendations](#411-visually-similar-recommendations)
Expand All @@ -42,6 +43,7 @@
- [6.5 Facets Filtering](#65-facets-filtering)
- [7. Event Tracking](#7-event-tracking)
- [7.1 Setup Tracking](#71-setup-tracking)
- [7.1.1 Setup for multiple placements](#711-setup-for-multiple-placements)
- [7.2 Send Events](#72--send-events)
- [8. Developer Notes](#8-developer-notes)

Expand All @@ -58,7 +60,7 @@ This SDK contains two sets of APIs that provide accurate, reliable and scalable

For source code and references, please visit the [Github Repository](https://github.com/visenze/visearch-sdk-swift).

> Current stable version: `1.10.2` (Swift 5+)
> Current stable version: `1.10.3` (Swift 5+)
>
> Supported iOS version: iOS 8.x and higher
Expand Down Expand Up @@ -102,41 +104,43 @@ Type a name for your project and press Next, here we use Demo as the project nam

First you need to install the CocoaPods Ruby gem:

```
```sh
# Xcode 7 + 8
sudo gem install cocoapods --pre
```

Then go to your project directory to create an empty Podfile
```

```sh
cd /path/to/Demo
pod init
```

Edit the Podfile as follow. Please update the version to the latest.
This is just a reference.

```
```sh
platform :ios, '12.0'
use_frameworks!

target '<Your Target Name>' do
pod 'ViSearchSDK', '~>1.10.2'
pod 'ViSearchSDK', '~>1.10.3'
end
...
```

Install the ViSearch SDK:

```
```sh
pod install
```

The Demo.xcworkspace project should be created.

#### 2.3.2 Using Carthage

1. Create a Cartfile in the same directory where your `.xcodeproj` or `.xcworkspace` is.
2. List the dependency as follow: `github "visenze/visearch-sdk-swift" ~> 1.10.2` . Please change the version to latest available version.
2. List the dependency as follow: `github "visenze/visearch-sdk-swift" ~> 1.10.3` . Please change the version to latest available version.
3. Run `carthage update --use-xcframeworks` or `carthage bootstrap --platform iOS --cache-builds --no-use-binaries --use-xcframeworks` . The command will fail as `ViSenzeAnalytics.xcframework` is not pulled as it is a dependency. We will resolve it in the next step.
4. A Cartfile.resolved file and a Carthage directory will appear in the same directory where your .xcodeproj or .xcworkspace is
5. Navigate to ViSearchSDK folder: `cd Carthage/Checkouts/visearch-sdk-swift/ViSearchSDK` which contains the source code for ViSearchSDK.
Expand All @@ -151,7 +155,7 @@ The Demo.xcworkspace project should be created.

You can also download the iOS [ViSearch SDK](https://github.com/visenze/visearch-sdk-swift/archive/master.zip) directly. To use it, unzip it and drag ViSearchSDK project (under ViSearchSDK folder) into your project. The ViSearchSDK project produces ViSearchSDK framework and has a dependency i.e. ViSenzeAnalytics. Before it can be used, you will need to run and pull ViSenzeAnalytics framework by running:

```
```sh
carthage update --use-xcframeworks
```

Expand Down Expand Up @@ -206,7 +210,7 @@ client = ViSearchClient(baseUrl: yourUrl, accessKey: accessKey, secret: secret)

Please init ViSearch client in this way if you connect to another endpoint rather than default (https://visearch.visenze.com)

```
```swift
client = ViSearchClient(baseUrl: "https://custom-visearch.yourdomain.com", accessKey: accessKey, secret: secret)
```

Expand Down Expand Up @@ -248,7 +252,17 @@ ViProductSearch.sharedInstance.client?.session = URLSession(configuration: (ViPr

```

#### 3.2.1 Setup for multiple placements

If you want to create multiple instances of ProductSearch, you can instantiate ViProductSearch multiple times

```swift
var placement111 = ViProductSearch()
placement111.setUp(appKey: "YOUR_KEY", placementId: YOUR_PLACEMENT_ID)

var placement222 = ViProductSearch()
placement222.setUp(appKey: "YOUR_KEY", placementId: YOUR_PLACEMENT_ID)
```

## 4. Solution APIs

Expand Down Expand Up @@ -870,7 +884,7 @@ let tracker = ViSearch.sharedInstance.newTracker(code: "your-code")

To get ViSenze autogenerated `uid` and session Id for analytics purposes, you can call

```
```swift
// get uid
ViProductSearch.sharedInstance.getUid()

Expand All @@ -879,6 +893,20 @@ ViProductSearch.sharedInstance.getSid()

```

#### 7.1.1 Setup for multiple placements

If you want to create multiple instances of tracker, you can instantiate ViSenzeTracker multiple times

```swift
var placement111 = ViProductSearch()
placement111.setUp(appKey: "YOUR_KEY", placementId: YOUR_PLACEMENT_ID)
var tracker111 = placement111.newTracker()

var placement222 = ViProductSearch()
placement222.setUp(appKey: "YOUR_KEY", placementId: YOUR_PLACEMENT_ID)
var tracker222 = placement222.newTracker()
```

### 7.2 Send Events

Currently we support the following event actions: `click`, `view`, `product_click`, `product_view`, `add_to_cart`, `add_to_wishlist` and `transaction`. The `action` parameter can be an arbitrary string and custom events can be sent.
Expand All @@ -887,7 +915,7 @@ Note that it is optional to send transaction ID, product image URL and product p

To send events, first retrieve the search query ID found in the search results call back:

```
```swift

successHandler: {
(data : ViResponseData?) -> Void in
Expand All @@ -902,7 +930,7 @@ successHandler: {
Then the linked events can be sent as follows:


```
```swift
# send product click
let productClickEvent = VaEvent.newProductClickEvent(queryId: "ViSearch reqid in API response", pid: "product ID", imgUrl: "product image URL", pos: 3)
tracker.sendEvent(productClickEvent) { (eventResponse, networkError) in
Expand Down Expand Up @@ -931,7 +959,7 @@ User action(s) can also be sent through an batch event handler.

A common use case for this batch event method is to group up all transactions by sending it in a batch. This SDK will automatically generate a transaction ID to group transactions as an order.

```
```swift
tracker.sendEvents(eventList)
```

Expand Down
2 changes: 1 addition & 1 deletion ViSearchSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |s|


s.name = "ViSearchSDK"
s.version = "1.10.2"
s.version = "1.10.3"
s.summary = "A Visual Search API solution (Swift SDK)"

s.description = <<-DESC
Expand Down
8 changes: 4 additions & 4 deletions ViSearchSDK/ViSearchSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = NKN6QECX9M;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -684,7 +684,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.10.2;
MARKETING_VERSION = 1.10.3;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11";
PRODUCT_BUNDLE_IDENTIFIER = com.visenze.ViSearchSDK;
Expand All @@ -699,7 +699,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 20;
CURRENT_PROJECT_VERSION = 21;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = NKN6QECX9M;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -718,7 +718,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.10.2;
MARKETING_VERSION = 1.10.3;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11";
PRODUCT_BUNDLE_IDENTIFIER = com.visenze.ViSearchSDK;
Expand Down
2 changes: 1 addition & 1 deletion ViSearchSDK/ViSearchSDK/Classes/ViProductSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ open class ViProductSearch : NSObject {
/// Placement ID
private var placementId : Int? = nil

private var client : ViProductSearchClient? = nil
public var client : ViProductSearchClient? = nil

/// Set up the SDK with the proper authentications, needs to be called first prior to any other SDK
/// functions
Expand Down

0 comments on commit afbcc67

Please sign in to comment.