Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sht 5366 dynamically initialize posthog #1

Merged
merged 6 commits into from
Apr 24, 2024

Conversation

Mastersam07
Copy link
Collaborator

💡 Motivation and Context

Posthog initialization can only be done natively from android manifest and info.plist. However, there are cases where user want to configure dynamically from the dart side.

A good example is loading the posthog api key and host from some 3rd party(say api or firebase remote config) and then setting up posthog.

The current setup does not allow

This PR aims at solving the above described issue.

💚 How did you test it?

With the example code, on an emulator.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

@Mastersam07 Mastersam07 merged commit 19f25ca into main Apr 24, 2024
@Mastersam07 Mastersam07 deleted the feature/sht-5366-dynamically-initialize-posthog branch April 24, 2024 20:31
private fun configure(call: MethodCall, result: Result) {
try {
val apiKey: String = call.argument("apiKey") ?: return result.error("Invalid API Key", "API Key is null or empty", null)
val host: String = call.argument("host") ?: return result.error("Invalid Host", "Host is null or empty", null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mastersam07 How about using the default host if the host is not passed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier in the file, there is an initPlugin method where we try to initialise the plugin using the values set in the android manifest. When the apiKey is not in the manifest, the initialisation is cancelled.

This leaves the developer to manually call configure and pass in the apiKey and host as required parameters.

Copy link
Collaborator Author

@Mastersam07 Mastersam07 Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just read your message again @shuttlers-ifiok . Will modify accordingly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shuttlers-ifiok this has been treated in #3

channel.setMethodCallHandler(this)
}

private fun initPlugin(applicationContext: Context) {
private fun initPlugin(context: Context) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shuttlers-ifiok here.

On start, the plugin tries to initialize using the values in the manifest. Where apiKey is empty, initialization process is aborted.

Leaving the developer to manually call configure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants