Skip to content

Commit

Permalink
imPiggie - Adding PostHog to iMessage extension & fix missing App Nam…
Browse files Browse the repository at this point in the history
…e in events

MessagesViewController
- willBecomeActive call setup
- send - capture & call flush
- onLaunchApp capture

imPiggie.xcodeProj
- added PostHog to Link Binary with Libraries build phase

PostHogPen
- setup disable sending device ID

App - info.plist
- added CFBundleDisplayName so App Name populated in Posthog events.
  • Loading branch information
AndyDentFree committed Dec 3, 2023
1 parent c7a5dd0 commit 9b1dcfb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion imPiggie/Common/PostHogPen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct PostHogPen {

configuration.captureApplicationLifecycleEvents = false
configuration.recordScreenViews = false

configuration.shouldSendDeviceID = false // we are very privacy-focused
PHGPostHog.setup(with: configuration)
trough = PHGPostHog.shared()
}
Expand Down
19 changes: 18 additions & 1 deletion imPiggie/imPiggie Code Change Diary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,21 @@ Main.storyboard
- added extra layout, FlushButton
- ViewController
- bind FlushButton to onFlushButton


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Adding PostHog to iMessage extension & fix missing App Name in events
2023-12-03

MessagesViewController
- willBecomeActive call setup
- send - capture & call flush
- onLaunchApp capture

imPiggie.xcodeProj
- added PostHog to Link Binary with Libraries build phase

PostHogPen
- setup disable sending device ID

App - info.plist
- added CFBundleDisplayName so App Name populated in Posthog events.
6 changes: 6 additions & 0 deletions imPiggie/imPiggie IM/MessagesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit
import os
import Messages
import PostHog

class MessagesViewController: MSMessagesAppViewController {

Expand Down Expand Up @@ -69,6 +70,7 @@ class MessagesViewController: MSMessagesAppViewController {

// Use this method to configure the extension and restore previously stored state.
os_log("willBecomeActive")
PostHogPen.setup()
}

override func didBecomeActive(with conversation: MSConversation) {
Expand Down Expand Up @@ -159,12 +161,14 @@ class MessagesViewController: MSMessagesAppViewController {
let message = MSMessage(session: session ?? MSSession())
message.layout = layout
message.url = urlComps.url
PostHogPen.trough?.capture("sending", properties: ["mood": mood.rawValue])
conversation.insert(message) { (error) in
if let error = error {
os_log("Error with MSConversation.insert(message)")
print(error)
}
}
PostHogPen.trough?.flush() // flush every time so events logged
dismiss()
}

Expand All @@ -191,6 +195,8 @@ class MessagesViewController: MSMessagesAppViewController {
// that was the case in XCode 10 at least
@IBAction func onLaunchApp(_ sender: Any) {
guard let url: URL = URL(string: "imPiggie://?arbitraryParam=nothingSpecial") else { return }
PostHogPen.trough?.capture("launch app")

self.extensionContext?.open(url, completionHandler: { (success: Bool) in
// nothing, we invoked the main app!
})
Expand Down
12 changes: 12 additions & 0 deletions imPiggie/imPiggie.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
42D078752B1C425F00FACC09 /* Secrets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42D078742B1C425F00FACC09 /* Secrets.swift */; };
42D078762B1C425F00FACC09 /* Secrets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42D078742B1C425F00FACC09 /* Secrets.swift */; };
42D078782B1C433000FACC09 /* PostHogPen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42D078772B1C433000FACC09 /* PostHogPen.swift */; };
42D0787A2B1C8FC600FACC09 /* PostHogPen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42D078772B1C433000FACC09 /* PostHogPen.swift */; };
42D0787C2B1C8FE300FACC09 /* PostHog in Frameworks */ = {isa = PBXBuildFile; productRef = 42D0787B2B1C8FE300FACC09 /* PostHog */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -89,6 +91,7 @@
buildActionMask = 2147483647;
files = (
42199E9021F1CA5600D4377E /* Messages.framework in Frameworks */,
42D0787C2B1C8FE300FACC09 /* PostHog in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -199,6 +202,9 @@
dependencies = (
);
name = "imPiggie IM";
packageProductDependencies = (
42D0787B2B1C8FE300FACC09 /* PostHog */,
);
productName = "imPiggie IM";
productReference = 42199E8D21F1CA5600D4377E /* imPiggie IM.appex */;
productType = "com.apple.product-type.app-extension.messages";
Expand Down Expand Up @@ -296,6 +302,7 @@
files = (
42199EA621F22CA400D4377E /* SharedData.swift in Sources */,
42D078762B1C425F00FACC09 /* Secrets.swift in Sources */,
42D0787A2B1C8FC600FACC09 /* PostHogPen.swift in Sources */,
42089153289E15FB0036C790 /* Mood.swift in Sources */,
42199E9321F1CA5600D4377E /* MessagesViewController.swift in Sources */,
);
Expand Down Expand Up @@ -586,6 +593,11 @@
package = 42D078712B1C40FE00FACC09 /* XCRemoteSwiftPackageReference "posthog-ios" */;
productName = PostHog;
};
42D0787B2B1C8FE300FACC09 /* PostHog */ = {
isa = XCSwiftPackageProductDependency;
package = 42D078712B1C40FE00FACC09 /* XCRemoteSwiftPackageReference "posthog-ios" */;
productName = PostHog;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 4201A9C421F0763B0043E369 /* Project object */;
Expand Down
2 changes: 2 additions & 0 deletions imPiggie/imPiggie/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleDisplayName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion imPiggie/imPiggie/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ViewController: UIViewController {

/// see Readme and https://developer.apple.com/documentation/messageui/mfmessagecomposeviewcontroller
@IBAction func onAppSendButton(_ sender: Any) {
PostHogPen.trough?.capture("send pressed to display message interface")
PostHogPen.trough?.capture("display message interface")
messager.displayMessageInterface(onVC: self, mood: lastTappedMood)
}

Expand Down

0 comments on commit 9b1dcfb

Please sign in to comment.