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

Add tvOS support; Add trackSiteSearch support; Make iOS/tvOS trackView implementation in sync with Android; Make Android trackEvent implementation in sync with iOS/tvOS #7

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

lorenc-tomasz
Copy link
Contributor

@lorenc-tomasz lorenc-tomasz commented Jun 24, 2024

Changelog:

  • Allow to build the project on tvOS (using react-native-tvos).
  • Add trackSiteSearch method
  • Fix the trackView method on iOS / tvOS to behave like on the Android. Make title parameter optional

On Android trackView looks like this:

  @ReactMethod
  public void trackView(String route, @Nullable String title, Promise promise) {
    try {
      String actualTitle = title == null ? route : title;
      getTrackHelper().screen(route).title(actualTitle).with(tracker);

      promise.resolve(null);
    } catch (Exception e) {
      promise.reject(e);
    }
  }

As you can see, it takes title if available or route. When we do deeper into SDK it looks like this:

    public TrackMe build() {
        if (this.mPath == null) {
            throw new IllegalArgumentException("Screen tracking requires a non-empty path");
        } else {
            TrackMe trackMe = (new TrackMe(this.getBaseTrackMe())).set(QueryParams.URL_PATH, this.mPath).set(QueryParams.ACTION_NAME, this.mTitle).set(QueryParams.CAMPAIGN_NAME, this.mCampaignName).set(QueryParams.CAMPAIGN_KEYWORD, this.mCampaignKeyword);
            if (this.mCustomVariables.size() > 0) {
                trackMe.set(QueryParams.SCREEN_SCOPE_CUSTOM_VARIABLES, this.mCustomVariables.toString());
            }

            Iterator var2 = this.mCustomDimensions.entrySet().iterator();

            while(var2.hasNext()) {
                Map.Entry<Integer, String> entry = (Map.Entry)var2.next();
                CustomDimension.setDimension(trackMe, (Integer)entry.getKey(), (String)entry.getValue());
            }

            return trackMe;
        }
    }

It sets route as path parameter:

.set(QueryParams.URL_PATH, this.mPath)

and it sets title as aaction name parameter:

set(QueryParams.ACTION_NAME, this.mTitle).

When we look into iOS implementation:

    /// Tracks a screenview.
    ///
    /// This method can be used to track hierarchical screen names, e.g. screen/settings/register. Use this to create a hierarchical and logical grouping of screen views in the Matomo web interface.
    ///
    /// - Parameter view: An array of hierarchical screen names.
    /// - Parameter url: The optional url of the page that was viewed.
    /// - Parameter dimensions: An optional array of dimensions, that will be set only in the scope of this view.
    public func track(view: [String], url: URL? = nil, dimensions: [CustomDimension] = []) {
        let event = Event(tracker: self, action: view, url: url, dimensions: dimensions, isCustomAction: false)
        queue(event: event)
    }
    
    ...
    
    self.url = url ?? tracker.contentBase?.appendingPathComponent(action.joined(separator: "/"))

You can see that view is set as action param and url param is build based on action. With the change trackView will run the same way on both plaforms as expected.

  • Make Android trackEvent implementation in sync with iOS/tvOS. iOS allows to set url as optional param. The same should be possible with Android.

@lorenc-tomasz lorenc-tomasz marked this pull request as ready for review June 24, 2024 13:09
@mav10
Copy link
Collaborator

mav10 commented Jul 4, 2024

Could you provide an example how it was handled previous and how it will be rendered now in Matomo?

And maybe add it to README.md to explain people how to use it correctly?

Because we previous use only route and it was enough for us 😄
even with nested navigators

@lorenc-tomasz lorenc-tomasz changed the title Add tvOS support; Add trackSiteSearch support; Make iOS/tvOS trackView implementation in sync with Android Add tvOS support; Add trackSiteSearch support; Make iOS/tvOS trackView implementation in sync with Android; Make Android trackEvent implementation in sync with iOS/tvOS Jul 11, 2024
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