import React, { Component } from 'react' import { Container, Table } from 'semantic-ui-react' import Moment from 'react-moment'; import util from '../util/util' export default class VisitorComponent extends Component { state = { id: "", entry: null, visitors: [] } componentWillMount() { this.setState({ id: this.props.match.params.id }) util.lookupEntry(this.props.match.params.id, entry => this.setState({ entry })) this.reloadVisitors() this.reloadInterval = setInterval(this.reloadVisitors, 1000) } componentWillUnmount() { clearInterval(this.reloadInterval) } reloadVisitors = () => { util.getVisitors(this.props.match.params.id, visitors => this.setState({ visitors })) } // getUTMSource is a function which generates the output for the utm[...] table column getUTMSource(visit) { return [visit.UTMSource, visit.UTMMedium, visit.UTMCampaign, visit.UTMContent, visit.UTMTerm] .map(value => value ? value : null) .filter(v => v) .map((value, idx, data) => value + (idx !== data.length - 1 ? ", " : "")) .join("") } render() { const { visitors, id, entry } = this.state return ( {entry &&

Entry with id '{id}' was created at {entry.CreatedOn} and redirects to '{entry.URL}'. Currently it has {visitors.length} visits.

} Timestamp IP User Agent Referer UTM (source, medium, campaign, content, term) {visitors && visitors.map((visit, idx) => {visit.Timestamp} {visit.IP} {visit.UserAgent} {visit.Referer} {this.getUTMSource(visit)} )}
) } }