browserid-ios

Almost a clone of https://github.com/amedia/browserid

For generating and providing a browser id and a browser visit id to a WebView.
Used e.g. in Common Schema in ADPLogger.

Usage

Installation

Click on File -> Swift Packages -> Add Package Dependency and type in the git repository’s URL.
Select branch master, the package’s products that you need, and add them to specific targets in your project.

Once you click on Finish, the Swift Package Dependencies section will show the newly added package.

Usage and requirements

import BrowserID

...

In a ViewController

Use method initBrowserId on the webView. Takes one param.

for: String. The domain/host to set the cookie on, if missing.

var webView: WKWebView!

...

override func viewWillAppear(_ animated: Bool) {

    super.viewWillAppear(animated)
    
    let plainURL = URL(string: AppConfig.urlEndpoints.homeScreen)!
        
    // Init domainBrowserId and domainVisitId, via BrowserID
    if let domain = plainURL.host {
        webView.initBrowserId(for: domain)
    }
    
    let request = URLRequest(url: url)
    configureCustomUserAgent(webView: webView) { [weak self] in
        self?.webView.load(request)
    }

    ...
}

More methods

BrowserID.shared.getBrowserId()

Get persisted BrowserID, uuid, (unique for app install).

BrowserID.shared.getVisitId()

Get visitID, refreshed each 30 mins, uuid.

BrowserID.shared.getLastSessionTimestamp()

Get lastSessionTimestamp, epoch time.

GitHub

View Github