Last active
July 5, 2018 19:59
-
-
Save ryanashcraft/e80ddb0b1bcde78f9abda394f5033a35 to your computer and use it in GitHub Desktop.
AmpliTunes with react-amplitude
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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