Skip to content

Commit

Permalink
v1.0.1 and README
Browse files Browse the repository at this point in the history
  • Loading branch information
barbayrak committed May 22, 2020
1 parent 5b7ed68 commit 2180190
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
2 changes: 1 addition & 1 deletion PapcornsAnalytics.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |spec|

spec.name = "PapcornsAnalytics"
spec.version = "1.0.0"
spec.version = "1.0.1"
spec.summary = "Papcorns Analytics Tool iOS SDK"

spec.description = "Internal Papcorns Analytics Tool iOS SDK"
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion PapcornsAnalytics/PapcornsAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class PapcornsAnalytics {
PapcornsAPILogEvent.init(eventName: eventName, eventParameters: eventParameters).request()
}

public static func logScreen(userId : String) {
public static func setUserId(userId : String) {
PapcornsConfigManager.shared.config.userId = userId
PapcornsAPISetUser.init(userId: userId).request()
}
Expand Down
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Papcorns Analytics iOS SDK -> Swift 5

Add the following line to your Podfile

```
pod 'PapcornsAnalytics'
```

# Integrate the SDK into your app


```
import PapcornsAnalytics
```

Initialize PapcornsAnalytics in the `didFinishLaunching` or `didFinishLaunchingWithOptions` method of your AppDelegate file

```
var appVersion = ""
if let versionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
appVersion = versionString
}
PapcornsAnalytics.configure(appId: "INSERT YOUR APP ID HERE", appVersion: appVersion)
```

Replace "INSERT YOUR APP ID HERE" string with id given to you

# Setting User Id

Before calling logEvent or logScreen you need to set `PapcornsAnalytics.logEvent` with parameters [String:Any] whenever you need to trigger an event like in app purchases or signups etc.. , if there is no parameter then leave it with blank dictionary which is [:] .In event naming convension start with lowercased letter

```
PapcornsAnalytics.setUserId(userId : "")
```

## IMPORTANT !!!!!

If you are using Revenuecat and Firebase as a receipt validation then you need also set Revenuecat userId because we are also getting logs from Revenuecat webhook .

So checking authentication everytime user goes into app might be a good idea with this function

```
func checkAuth(){
let cUser = Auth.auth().currentUser
if(cUser != nil){
PapcornsAnalytics.setUserId(userId: cUser!.uid)
Purchases.shared.identify(cUser!.uid, { (info, error) in
if let e = error {
print("Sign in error: \(e.localizedDescription)")
}
})
self.continueToSomething()
}else{
Auth.auth().signInAnonymously { (result, err) in
PapcornsAnalytics.setUserId(userId: (result?.user.uid)!)
Purchases.shared.identify((result?.user.uid)!, { (info, error) in
if let e = error {
print("Sign in error: \(e.localizedDescription)")
}
})
self.continueToSomething()
}
}
}
```

# Tracking Screens

In `viewDidAppear` function of your viewcontroller call `PapcornsAnalytics.logScreen` with parameters [String:Any] , if there is no parameter then leave it with blank dictionary which is [:]

Setting a screenName parameter has a naming convention which is to put you context name first and then put "Screen" on top of it . For example if i am in HomeViewController log screen with name "HomeScreen". In log screen event naming start with uppercase letter

```
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
PapcornsAnalytics.logScreen(screenName: "XScreen", screenParameters: [:])
}
```

# Tracking Events

Call `PapcornsAnalytics.logEvent` with parameters [String:Any] whenever you need to trigger an event like in app purchases or signups etc.. , if there is no parameter then leave it with blank dictionary which is [:] .In event naming convension start with lowercased letter

```
PapcornsAnalytics.logEvent(eventName: "effectTapped", eventParameters:
[
"effectName" : "Harry Potter",
"effectId" : "1sae1123asgasr"
]
)
OR
PapcornsAnalytics.logEvent(eventName: "weekly_trial_bought", eventParameters: [:])
```

0 comments on commit 2180190

Please sign in to comment.