Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #61 from dart-lang/add_param
Browse files Browse the repository at this point in the history
add a analyticsUrl parameter
  • Loading branch information
devoncarew committed Jan 20, 2016
2 parents 4fd8ef7 + 4a47109 commit 98f773d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.2.0
- added an optional `analyticsUrl` parameter to the usage constructors

## 1.1.0
- fix two strong mode analysis issues (overrridding a field declaration with a
setter/getter pair)
Expand Down
18 changes: 14 additions & 4 deletions lib/src/usage_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ThrottlingBucket {
}

abstract class AnalyticsImpl extends Analytics {
static const String _GA_URL = 'https://www.google-analytics.com/collect';
static const String _defaultAnalyticsUrl = 'https://www.google-analytics.com/collect';

/// Tracking ID / Property ID.
final String trackingId;
Expand All @@ -74,12 +74,22 @@ abstract class AnalyticsImpl extends Analytics {

final List<Future> _futures = [];

AnalyticsImpl(this.trackingId, this.properties, this.postHandler,
{String applicationName, String applicationVersion}) {
String _url;

AnalyticsImpl(
this.trackingId,
this.properties,
this.postHandler, {
String applicationName,
String applicationVersion,
String analyticsUrl
}) {
assert(trackingId != null);

if (applicationName != null) setSessionValue('an', applicationName);
if (applicationVersion != null) setSessionValue('av', applicationVersion);

_url = analyticsUrl ?? _defaultAnalyticsUrl;
}

bool get optIn => properties['optIn'] == true;
Expand Down Expand Up @@ -189,7 +199,7 @@ abstract class AnalyticsImpl extends Analytics {
args['cid'] = _clientId;
args['t'] = hitType;

return _recordFuture(postHandler.sendPost(_GA_URL, args));
return _recordFuture(postHandler.sendPost(_url, args));
} else {
return new Future.value();
}
Expand Down
12 changes: 9 additions & 3 deletions lib/usage_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ export 'usage.dart';

/**
* An interface to a Google Analytics session, suitable for use in web apps.
*
* [analyticsUrl] is an optional replacement for the default Google Analytics
* URL (`https://www.google-analytics.com/collect`).
*/
class AnalyticsHtml extends AnalyticsImpl {
AnalyticsHtml(String trackingId, String applicationName, String applicationVersion) :
super(
AnalyticsHtml(String trackingId, String applicationName, String applicationVersion, {
String analyticsUrl
}) : super(
trackingId,
new HtmlPersistentProperties(applicationName),
new HtmlPostHandler(),
applicationName: applicationName,
applicationVersion: applicationVersion) {
applicationVersion: applicationVersion,
analyticsUrl: analyticsUrl
) {
int screenWidth = window.screen.width;
int screenHeight = window.screen.height;

Expand Down
20 changes: 13 additions & 7 deletions lib/usage_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ export 'usage.dart';
/**
* An interface to a Google Analytics session, suitable for use in command-line
* applications.
*
* [analyticsUrl] is an optional replacement for the default Google Analytics
* URL (`https://www.google-analytics.com/collect`).
*/
class AnalyticsIO extends AnalyticsImpl {
AnalyticsIO(String trackingId, String applicationName, String applicationVersion) :
super(
trackingId,
new IOPersistentProperties(applicationName),
new IOPostHandler(),
applicationName: applicationName,
applicationVersion: applicationVersion);
AnalyticsIO(String trackingId, String applicationName, String applicationVersion, {
String analyticsUrl
}) : super(
trackingId,
new IOPersistentProperties(applicationName),
new IOPostHandler(),
applicationName: applicationName,
applicationVersion: applicationVersion,
analyticsUrl: analyticsUrl
);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# BSD-style license that can be found in the LICENSE file.

name: usage
version: 1.1.0
version: 1.2.0
description: A Google Analytics wrapper for both command-line and web apps.
homepage: https://github.com/dart-lang/usage
author: Dart Team <misc@dartlang.org>
Expand Down

0 comments on commit 98f773d

Please sign in to comment.