Skip to content

Instantly share code, notes, and snippets.

@ryanashcraft
Last active July 5, 2018 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanashcraft/e80ddb0b1bcde78f9abda394f5033a35 to your computer and use it in GitHub Desktop.
Save ryanashcraft/e80ddb0b1bcde78f9abda394f5033a35 to your computer and use it in GitHub Desktop.
AmpliTunes with react-amplitude
import React, { Fragment } from "react";
import { Amplitude, LogOnMount } from "@amplitude/react-amplitude";
const NowPlayingView = props => {
return (
<Amplitude
// All events logged in this subtree will include these event properties
eventProperties={inheritedProps => ({
...inheritedProps,
"song id": props.songId,
"genre id": props.genreId,
"playlist id": props.playlistId,
"is song favorited": props.isFavorited,
"time elapsed": props.getTimeElapsed()
})}
>
{/* Log an event when this view mounts */}
<LogOnMount eventType="view now playing screen" />
{/* Log an event when the song changes */}
<LogOnChange value={props.songId} eventType="play song" />
<PlayControls />
</Amplitude>
);
};
const PlayControls = props => {
return (
<div>
<Seeker />
<div>
<RewindButton />
<PlayPauseButton />
<FastForwardButton />
</div>
<div>
<ShareMenu />
</div>
</div>
);
};
const FastForwardButton = props => {
return (
<Amplitude>
{({ instrument }) => (
// Log an event when this button is clicked
<Button onClick={instrument("fast forward", props.fastForward)}>
<Icon name="FAST_FORWARD" />
</Button>
)}
</Amplitude>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment