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

Support siteId per tracking request #116

Merged
merged 10 commits into from
Apr 16, 2024
Merged

Conversation

wzieba
Copy link
Collaborator

@wzieba wzieba commented Apr 5, 2024

Closes: #115

Description

This PR introduces a possibility for SDK users to provide a custom siteId whenever they record a pixel/track event.

This will also align to iOS, which supports this feature already

https://github.com/Parsely/AnalyticsSDK-iOS/blob/9b9db5478996582fdbd07d5aa4a2da0134f9ffe7/Sources/ParselyTracker.swift#L47-L48

Design

I've decided to propose more verbose API and introduce SiteIdSource instead of a String which is empty by default. I think this way it's easier for SDK users to understand the behavior.

Backwards compatibility

Because we cannot introduce @JvmOverloads on interface methods, this change will be breaking for Java users. But I think this is acceptable - I plan to release 4.1.0 after this (not bumping major version). In the case of Java users, addressing breaking changes will be as easy as providing SiteIdSource.Default.INSTANCE in tracking methods.

Test

This PR introduces unit tests and functional test case for engagement manager case. We can also test this with example app:

  1. Run the example app
  2. Provide some value in "Custom site id" edit text
  3. Tap on "Track URL", then press "Start engagement"
  4. Observe in logs that after ~15 seconds you should see logs that would be sent to the backend. Make sure they have idsite equal to the custom id you provided in step 2.

@wzieba wzieba marked this pull request as ready for review April 5, 2024 13:26
@wzieba
Copy link
Collaborator Author

wzieba commented Apr 5, 2024

hi @iangmaia 👋 would you be ok reviewing this PR?

@wzieba wzieba requested a review from iangmaia April 5, 2024 13:27
Comment on lines +25 to +26
uuid: String,
siteIdSource: SiteIdSource,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Parameter docs for these two are missing.
Perhaps adding more details specially on how siteIdSource works with its default can also be helpful.

@@ -36,12 +36,14 @@ public interface ParselyTracker {
* content). Do not use this for **content also hosted on** URLs Parse.ly
* would normally crawl.
* @param extraData A Map of additional information to send with the event.
* @param siteIdSource The source of the site ID to use for the event.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps it is worth it to add / repeat / emphasize a bit more info on siteId and what's the default behavior?

@wzieba
Copy link
Collaborator Author

wzieba commented Apr 16, 2024

Thanks @iangmaia ! I've added and extended comments, ready for another round 👍

Copy link

codecov bot commented Apr 16, 2024

Codecov Report

Attention: Patch coverage is 63.15789% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 70.46%. Comparing base (3ae9382) to head (9af20d9).
Report is 1 commits behind head on main.

Files Patch % Lines
...m/parsely/parselyandroid/ParselyTrackerInternal.kt 0.00% 5 Missing ⚠️
.../java/com/parsely/parselyandroid/ParselyTracker.kt 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #116      +/-   ##
==========================================
- Coverage   70.54%   70.46%   -0.09%     
==========================================
  Files          21       22       +1     
  Lines         404      413       +9     
  Branches       49       51       +2     
==========================================
+ Hits          285      291       +6     
- Misses        104      107       +3     
  Partials       15       15              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -31,7 +35,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);

// initialize the Parsely tracker with your site id and the current Context
ParselyTracker.init("example.com", 30, this, true);
ParselyTracker.init(DEFAULT_SITE_ID, 30, this, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if ParselyTracker.init() shouldn't also receive a SiteIdSource 🤔
Are there reasons not to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because we need some site id to be defined. If ParselyTracker.init() received SiteIdSource, then API consumer could pass SiteIdSource.Default, which would have to be supported and it's not a valid state.

Alternatively, we could make ParselyTracker.init() receive SiteIdSource.Custom, but I think it only shadows implementation and causes confusion as it can raise a question: "custom" to what? In ParselyTracker.trackPageview it's "custom" to the value provided in initialization, so it makes sense there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because we need some site id to be defined. If ParselyTracker.init() received SiteIdSource, then API consumer could pass SiteIdSource.Default, which would have to be supported and it's not a valid state.

Alternatively, we could make ParselyTracker.init() receive SiteIdSource.Custom, but I think it only shadows implementation and causes confusion as it can raise a question: "custom" to what? In ParselyTracker.trackPageview it's "custom" to the value provided in initialization, so it makes sense there.

Got it! Makes sense 👍

@wzieba wzieba merged commit 47696a4 into main Apr 16, 2024
3 checks passed
@wzieba wzieba deleted the support_site_id_per_request branch April 16, 2024 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] Support multiple Site IDs within one app
2 participants