# expo-analytics-google

> Google Analytics integration for use with React Native apps built on Expo

Latest version **1.0.4** (published 2019-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install expo-analytics-google
pnpm add expo-analytics-google
yarn add expo-analytics-google
bun add expo-analytics-google
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-11-26 |
| First published | 2019-11-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Medius Software |
| Maintainers | mediusoft |
| Keywords | react, native, expo, google, analytics |

## Links

- npm: https://www.npmjs.com/package/expo-analytics-google
- Repository: https://github.com/mediusoft/expo-analytics-google
- Homepage: https://github.com/mediusoft/expo-analytics-google#readme
- Issues: https://github.com/mediusoft/expo-analytics-google/issues
- npm.io page: https://npm.io/package/expo-analytics-google

## Dependencies (1)

- [expo-constants](https://npm.io/package/expo-constants.md) ^7.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2019-11-26
- 1.0.3 — 2019-11-13
- 1.0.2 — 2019-11-11
- 1.0.1 — 2019-11-11
- 1.0.0 — 2019-11-11

## README

[![npm version](https://badge.fury.io/js/expo-analytics-google.svg)](https://badge.fury.io/js/expo-analytics-google)

Expo Analytics
=========

Google Analytics integration for use with React Native apps built on Expo. This library does not require linking.

Please create issues for any bugs you find or features you would like added.

## Installation

```
npm install expo-analytics-google --save
```

## Usage

Your React Native app's screen resolution, app name, app ID, app version and multiple other parameters will be automatically resolved and sent with each hit or event.
```
import { Analytics } from 'expo-analytics-google';

await Analytics.init({ propertyId: 'UA-XXXXXX-Y' });
```

## More Options

You might want to use your own static userAgent http header instead of the default WebView header.
```
import { Analytics } from 'expo-analytics-google';

await Analytics.init({ propertyId: 'UA-XXXXXX-Y', config: { userAgent: 'Custom UserAgent', debug: true } });
```

##### Hits 

Sending page hits or screen hits is done by constructing a new `PageHit` or `ScreenHit` instance and passing it to the `hit` function of an `Analytics` instance.

```
import { Analytics, PageHit } from 'expo-analytics-google';

Analytics.hit(new PageHit('Home'));
```

##### Events

You can also send custom events by constructing a new `Event` instance and passing it to the `event` function.  Events have four parameters. 

* Event Category
* Event Action
* Event Label (optional, but recommended)
* Event Value (optional, integer)

These parameters are passed to the `Event` constructor in that order.  

```
import { Analytics, Event } from 'expo-analytics-google';

Analytics.event(new Event('Video', 'Play', 'The Big Lebowski', 123));
```

[Learn more](https://support.google.com/analytics/answer/1033068?hl=en) about custom events.

##### Custom Dimensions

[Custom Dimensions](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cd_) are also supported.  Any custom dimensions set will be sent with each request.

```
import { Analytics, Event } from 'expo-analytics-google';

const customDimensions = [];
customDimensions[1] = 'TrialAccount';
customDimensions[2] = 'Comedy';
Analytics.event(new Event('Video', 'Play', 'The Big Lebowski', 123), { customDimensions });
```

##### Custom Metrics

[Custom Metrics](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cm_) work the same way with just a slightly different call.

```
import { Analytics, Event } from 'expo-analytics-google';

const customMetrics = [];
customMetrics[1] = 15;
Analytics.event(new Event('Video', 'Play', 'The Big Lebowski', 123), { customMetrics });
```

##### Additional Parameters

You can also optionally include any additional [supported parameters](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters) you would like.

```
import { Analytics } from 'expo-analytics-google';

// pass in the user ID (uid), user locale (ul), referrer (dr) and campaign name (cn) 
await Analytics.init({ propertyId: 'UA-XXXXXX-Y', parameters: { uid: '999', dr: 'github.com', cn: 'get_more_views' } });
```

##### Ecommerce tracking 
###### Transaction hit type
You can also send purchase by constructing a new `Transaction` instance and passing it to the `transaction` function.  Transaction have five parameters. 

* id (Required, string)
* affiliation (Optional, string)
* revenue (Optional, currency, but recommended)
* shipping (Optional, currency)
* tax (Optional, currency)

These parameters are passed to the `Transaction` constructor in that order.

```
import { Analytics, Transaction } from 'expo-analytics-google';

Analytics.hit(new Transaction('1235', 'Store', 38.43, 1.29, 5));
```

###### Item hit type
You can also send along the purchase the products that were purchased in the transaction, constructing a new `AddItem` instance and passing it to the `AddItem` function. 'AddItem' have six parameters. 

* id (The transaction id, Required, string)
* name (Required, string)
* price (Optional, currency, but recommended)
* quantity (Optional, integer)
* sku (Optional, string, but recommended)
* category (Optional, string, but recommended)

These parameters are passed to the `AddItem` constructor in that order.

```
import { Analytics, AddItem } from 'expo-analytics-google';

Analytics.hit(new AddItem('1235', 'T-SHIRT', 11.99, 1, 'DD44', 'Clothes'));
```

## Debugging

The Google Analytics API is a bit particular.  If you're not seeing Real Time hits in your Analytics console you can turn on debug mode for this package and the exact URL request being sent will be printed to the `console`.

```
import { Analytics, PageHit } from 'expo-analytics-google';

await Analytics.init({ propertyId: 'UA-XXXXXX-Y', config: { debug: true } });

...

Analytics.hit(new PageHit('IsItWorking'));
``` 

## Release History

* 1.0.2 Initial release

---
_Source: https://npm.io/package/expo-analytics-google · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
