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

Cleaned up README with improved markdown formatting #6

Merged
merged 1 commit into from
Dec 4, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 78 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,66 @@

## Installation:

Follows the [Cordova Plugin spec](https://github.com/alunny/cordova-plugin-spec), abd it works with [Pluginstall](https://github.com/alunny/pluginstall).
Follows the [Cordova Plugin spec](https://github.com/alunny/cordova-plugin-spec), abd it works with [Pluginstall](https://github.com/alunny/pluginstall).

To install it to your app,
simply execute pluginstall as follows;
To install it to your app, simply execute pluginstall as follows:

pluginstall [PLATFORM] [TARGET-PATH] [PLUGIN-PATH]

where
[PLATFORM] = ios or android
[TARGET-PATH] = path to folder containing your phonegap project
[PLUGIN-PATH] = path to folder containing this plugin

where:

* `[PLATFORM]` = ios or android
* `[TARGET-PATH]` = path to folder containing your phonegap project
* `[PLUGIN-PATH]` = path to folder containing this plugin

## Usage
The plugin creates the object `window.plugins.gaPlugin
The plugin creates the object `window.plugins.gaPlugin`

After onDeviceReady, create a local var and startup the plugin like so;
### Initializing

var gaPlugin;
After onDeviceReady, create a local var and startup the plugin like so:

```javascript
var gaPlugin;

function onDeviceReady() {
gaPlugin = window.plugins.gaPlugin;
gaPlugin.init(successHandler, errorHandler, "UA-12345678-1", 10);
gaPlugin = window.plugins.gaPlugin;
gaPlugin.init(successHandler, errorHandler, "UA-12345678-1", 10);
}
```

To get things rolling you need to call init() when your device ready function fires.
Init takes 4 arguments;
1) success - a function that will be called on success
2) fail - a function that will be called on error.
3) id - Your Google Analytics account ID of the form; UA-XXXXXXXX-X
This is the account ID you were given when you signed up.
4) period - An integer containing the minimum number of seconds
between upload of metrics. When metics are logged, they are enqued
and are sent out in batches based on this value. You'll want to
avoid setting this value too low, to limit the overhead of sending data.
Ex;
gaPlugin.init(successHandler, errorHandler, "UA-12345678-1", 10);

Init takes 4 arguments:

1. success - a function that will be called on success
1. fail - a function that will be called on error.
1. id - Your Google Analytics account ID of the form; UA-XXXXXXXX-X<br/>This is the account ID you were given when you signed up.
1. period - An integer containing the minimum number of seconds between upload of metrics. When metics are logged, they are enqued and are sent out in batches based on this value. You'll want to avoid setting this value too low, to limit the overhead of sending data.

Ex:

```javascript
gaPlugin.init(successHandler, errorHandler, "UA-12345678-1", 10);
```

### Tracking Events

To track an event, call (oddly enough) trackEvent().
trackEvent takes 6 arguments;

1) resultHandler - a function that will be called on success
2) errorHandler - a function that will be called on error.
3) category - This is the type of event you are sending such as "Button", "Menu", etc.
4) eventAction - This is the type of event you are sending such as "Click", "Select". etc.
5) eventLabel - A label that describes the event such as Button title or Menu Item name.
6) eventLabel - A label that describes the event such as Button title or Menu Item name.
7) eventValue - An application defined integer value that can mean whatever you want it to mean.
1. resultHandler - a function that will be called on success
1. errorHandler - a function that will be called on error.
1. category - This is the type of event you are sending such as "Button", "Menu", etc.
1. eventAction - This is the type of event you are sending such as "Click", "Select". etc.
1. eventLabel - A label that describes the event such as Button title or Menu Item name.
1. eventValue - An application defined integer value that can mean whatever you want it to mean.

Ex;
gaPlugin.trackEvent( nativePluginResultHandler, nativePluginErrorHandler, "Button", "Click", "event only", 1);
Ex:

```javascript
gaPlugin.trackEvent( nativePluginResultHandler, nativePluginErrorHandler, "Button", "Click", "event only", 1);
```
### Setting Arbitrary Data

TrackEvent covers most of what you need, but there may be cases where you want to pass arbitrary data.
setVariable() lets you pass key/value pairs (Up to 4 on free accounts, up to 50 on paid accounts).
Expand All @@ -63,34 +73,48 @@ the previous value. Passing an index out of range fails silently, with no data s
trackEvent, after which those indexes will be available for reuse.
setVariable() accepts 5 arguments;

1) resultHandler - a function that will be called on success
2) errorHandler - a function that will be called on error.
3) key - this is the identifying key for the value you are passing.
4) value - Arbitrary string data associated with the key and index.
5) index - the numerical index representing on of your variable slots (1-4 or 1-50, depending on the account type)
1. resultHandler - a function that will be called on success
1. errorHandler - a function that will be called on error.
1. key - this is the identifying key for the value you are passing.
1. value - Arbitrary string data associated with the key and index.
1. index - the numerical index representing on of your variable slots (1-4 or 1-50, depending on the account type)

Ex:

```javascript
gaPlugin.setVariable( nativePluginResultHandler, nativePluginErrorHandler, "favoriteColor", "Purple", 1);
```

### Tracking Pages

Ex;
gaPlugin.setVariable( nativePluginResultHandler, nativePluginErrorHandler, "favoriteColor", "Purple", 1);

In addition to events and variables, you can also log page visits with trackPage(). Unlike variables, howver, page hits do not require
a subsequent call to trackEvent() as they are considered unique events in an of themselves.
a subsequent call to trackEvent() as they are considered unique events in and of themselves.
trackPage() takes 3 arguments;

1) resultHandler - a function that will be called on success
2) errorHandler - a function that will be called on error.
3) url - The url of the page hit you are logging.
1. resultHandler - a function that will be called on success
1. errorHandler - a function that will be called on error.
1. url - The url of the page hit you are logging.

Ex:

```javascript
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "some.url.com");
```

### Shutting Down

Ex;
gaPlugin.trackPage( nativePluginResultHandler, nativePluginErrorHandler, "some.url.com");

Finally, when your app shuts down, you'll want to cleanup after yourselve by calling exit();
exit() accepts 2 arguments;

1) resultHandler - a function that will be called on success
2) errorHandler - a function that will be called on error.
Ex;
gaPlugin.exit(nativePluginResultHandler, nativePluginErrorHandler);

1. resultHandler - a function that will be called on success
1. errorHandler - a function that will be called on error.

Ex:

```javascript
gaPlugin.exit(nativePluginResultHandler, nativePluginErrorHandler);
```

This package includes an Example folder containing an index.html file showing how all of this fits together.
Note that the contents of Examples does not get installed anywhere by pluginstall. Its just there to provide a usage example.

Expand Down