npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@davidyaha/expo-analytics

v1.0.9

Published

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

Downloads

5

Readme

npm version

Expo Analytics

Google Analytics integration for use with React Native apps built on Expo. Most of the other Google Analytics libraries I've found require linking, which is not supported with 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 --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.

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';

const analytics = new Analytics('UA-XXXXXX-Y');
analytics.hit(new PageHit('Home'))
  .then(() => console.log("success"))
  .catch(e => console.log(e.message));
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';

const analytics = new Analytics('UA-XXXXXX-Y');
analytics.event(new Event('Video', 'Play', 'The Big Lebowski', 123))
  .then(() => console.log("success"))
  .catch(e => console.log(e.message));

Learn more about custom events.

Custom Dimensions

Custom Dimensions are also supported. Any custom dimensions set will be sent with each request.

import { Analytics, Event } from 'expo-analytics';

const analytics = new Analytics('UA-XXXXXX-Y');
analytics.addCustomDimension(1, 'TrialAccount');
analytics.addCustomDimension(2, 'Comedy');
analytics.event(new Event('Video', 'Play', 'The Big Lebowski', 123))
  .then(() => console.log("success"))
  .catch(e => console.log(e.message));

You can remove custom dimensions as needed.

analytics.removeCustomDimension(1);
Additional Parameters

You can also optionally include any additional supported parameters you would like.

import { Analytics } from 'expo-analytics';

// pass in the user ID (uid), referrer (dr) and campaign name (cn) 
const analytics = new Analytics('UA-XXXXXX-Y', { uid: '999', dr: 'github.com', cn: 'get_more_views' });

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';

const analytics = new Analytics('UA-XXXXXX-Y', null, { debug: true });
analytics.hit(new PageHit('IsItWorking'))
  .then(() => console.log("success"))
  .catch(e => console.log(e.message));

Release History

  • 1.0.7 Promisification. Thanks, @dylancompanjen!

  • 1.0.6 Fix for ScreenHit parameter name (thanks @davisml!). Support for custom dimensions.

  • 1.0.5 Fixing issue with duplicate dependencies causing installation problems.

  • 1.0.4 Automatically pull screen resolution from React Native dimensions. Resolve app name, app ID, app version from Expo manifest. App name is now required. Added debug option.

  • 1.0.3 Added support for app ID and version

  • 1.0.2 Added support for custom events

  • 1.0.1 Initial release