Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
TesteurManiak committed Oct 12, 2023
2 parents 983ce99 + a97903f commit adb379c
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 11 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## [4.1.1]

* Bump device_info_plus from 9.0.3 to 10.0.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/123
* Bump package_info_plus from 4.1.0 to 5.0.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/122
* chore: bump dependencies, fix formatting by @TesteurManiak in https://github.com/Floating-Dartists/matomo-tracker/pull/124


**Full Changelog**: https://github.com/Floating-Dartists/matomo-tracker/compare/4.1.0...4.1.1

## [4.1.0]

* Bump custom_lint from 0.4.0 to 0.5.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/114
* Bump mocktail from 0.3.0 to 1.0.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/116
* feat: fixed README and bumped dependencies by @TesteurManiak in https://github.com/Floating-Dartists/matomo-tracker/pull/118
* Feat: Change url on the fly by @TesteurManiak in https://github.com/Floating-Dartists/matomo-tracker/pull/120


**Full Changelog**: https://github.com/Floating-Dartists/matomo-tracker/compare/4.0.0...4.1.0

## [4.0.0]

**Check the [Migration Guide](https://github.com/Floating-Dartists/matomo-tracker#v400) to learn about breaking changes in this version**
Expand Down
2 changes: 1 addition & 1 deletion lib/src/campaign.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:matomo_tracker/src/assert.dart';
/// Describes a campaign.
///
/// Multiple `track...` methods in [MatomoTracker] can take a campaign as argument.
///
///
/// When using campaigns, it should be noted that each visit can only have at most
/// one campaign associated with it. It does not matter if the first `track...`
/// call or a subsequent `track...` call has the campaign attached, it will be treated
Expand Down
28 changes: 26 additions & 2 deletions lib/src/matomo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class MatomoTracker {

late final PlatformInfo _platformInfo;

@visibleForTesting
MatomoDispatcher get dispatcher => _dispatcher;

late MatomoDispatcher _dispatcher;

static final instance = MatomoTracker._internal();
Expand All @@ -61,7 +64,28 @@ class MatomoTracker {
/// Should not be confused with the `url` tracking parameter
/// which is constructed by combining [contentBase] with a `path`
/// (e.g. in [trackPageViewWithName]).
late final String url;
///
/// You can use [setUrl] to change this value after initialization.
String get url {
if (_url case final url?) {
return url;
}
throw const UninitializedMatomoInstanceException();
}

String? _url;

/// Sets the url of the Matomo endpoint and updates the dispatcher.
///
/// Note that this will change the url used by the request that are still
/// in the queue.
void setUrl(String newUrl) {
_initializationCheck();

_url = newUrl;
_dispatcher = _dispatcher.copyWith(baseUrl: newUrl);
}

late final Session session;

Visitor get visitor => _visitor;
Expand Down Expand Up @@ -223,7 +247,7 @@ class MatomoTracker {
log.setLogging(level: verbosityLevel);

this.siteId = siteId;
this.url = url;
_url = url;
this.customHeaders = customHeaders;
_pingInterval = pingInterval;
_lock = sync.Lock();
Expand Down
16 changes: 16 additions & 0 deletions lib/src/matomo_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,20 @@ class MatomoDispatcher {

return baseUri.replace(queryParameters: queryParameters);
}

MatomoDispatcher copyWith({
String? baseUrl,
String? tokenAuth,
String? userAgent,
Logger? log,
http.Client? httpClient,
}) {
return MatomoDispatcher(
baseUrl: baseUrl ?? baseUri.toString(),
tokenAuth: tokenAuth ?? this.tokenAuth,
userAgent: userAgent ?? this.userAgent,
log: log ?? this.log,
httpClient: httpClient ?? this.httpClient,
);
}
}
16 changes: 8 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: matomo_tracker
description: A fully cross-platform wrap of the Matomo tracking client for
Flutter, using the Matomo API.
version: 4.0.0
version: 4.1.1
homepage: https://github.com/Floating-Dartists/matomo-tracker
repository: https://github.com/Floating-Dartists/matomo-tracker
issue_tracker: https://github.com/Floating-Dartists/matomo-tracker/issues
Expand All @@ -15,21 +15,21 @@ environment:

dependencies:
clock: ^1.1.1
collection: ^1.17.1
device_info_plus: ^9.0.3
collection: ^1.17.2
device_info_plus: ">=9.0.3 <11.0.0"
flutter:
sdk: flutter
http: ^1.1.0
package_info_plus: ^4.1.0
shared_preferences: ^2.2.0
package_info_plus: ">=4.1.0 <6.0.0"
shared_preferences: ^2.2.2
uuid: ^3.0.7

dev_dependencies:
custom_lint: ">=0.4.0 <0.6.0"
fd_lints: ^2.1.0
custom_lint: ^0.5.3
fd_lints: ^2.2.0
flutter_test:
sdk: flutter
meta: ^1.9.1
mocktail: ^1.0.0
mocktail: ^1.0.1

flutter: null
40 changes: 40 additions & 0 deletions test/src/matomo_dispatcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,44 @@ void main() {
),
);
});

group('copyWith', () {
test('should copy with new url', () {
const newUrl = 'https://test.com';

final initialDispatcher = MatomoDispatcher(
baseUrl: matomoDispatcherBaseUrl,
userAgent: matomoTrackerUserAgent,
tokenAuth: matomoDispatcherToken,
httpClient: mockHttpClient,
log: mockLogger,
);

final newDispatcher = initialDispatcher.copyWith(baseUrl: newUrl);

expect(newDispatcher.baseUri.toString(), newUrl);
expect(newDispatcher.userAgent, matomoTrackerUserAgent);
expect(newDispatcher.tokenAuth, matomoDispatcherToken);
expect(newDispatcher.httpClient, mockHttpClient);
expect(newDispatcher.log, mockLogger);
});

test('should do nothing', () {
final initialDispatcher = MatomoDispatcher(
baseUrl: matomoDispatcherBaseUrl,
userAgent: matomoTrackerUserAgent,
tokenAuth: matomoDispatcherToken,
httpClient: mockHttpClient,
log: mockLogger,
);

final newDispatcher = initialDispatcher.copyWith();

expect(newDispatcher.baseUri.toString(), matomoDispatcherBaseUrl);
expect(newDispatcher.userAgent, matomoTrackerUserAgent);
expect(newDispatcher.tokenAuth, matomoDispatcherToken);
expect(newDispatcher.httpClient, mockHttpClient);
expect(newDispatcher.log, mockLogger);
});
});
}
29 changes: 29 additions & 0 deletions test/src/matomo_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:matomo_tracker/src/content.dart';
import 'package:matomo_tracker/src/event_info.dart';
import 'package:matomo_tracker/src/exceptions.dart';
import 'package:matomo_tracker/src/matomo.dart';
import 'package:mocktail/mocktail.dart';

Expand Down Expand Up @@ -474,4 +475,32 @@ void main() {
},
);
});

group('url getter', () {
test('should throw if not initialized', () {
expect(
() => MatomoTracker().url,
throwsA(isA<UninitializedMatomoInstanceException>()),
);
});
});

group('setUrl', () {
test('should throw if not initialized', () {
expect(
() => MatomoTracker().setUrl(''),
throwsA(isA<UninitializedMatomoInstanceException>()),
);
});

test('should set the new url and dispatcher', () async {
const newUrl = 'https://test.com';
final tracker = await getInitializedMatomoTracker();

tracker.setUrl(newUrl);

expect(tracker.url, newUrl);
expect(tracker.dispatcher.baseUri.toString(), newUrl);
});
});
}

0 comments on commit adb379c

Please sign in to comment.