Created
December 13, 2017 17:29
-
-
Save AubreyF/17f22ab0d39a65685936ee50976852fe to your computer and use it in GitHub Desktop.
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, {Component} from 'react'; | |
import {connect} from 'react-redux'; | |
import PropTypes from "prop-types"; | |
class CustomerSupportManager extends Component { | |
static propTypes = { | |
authUser: PropTypes.object.isRequired, | |
}; | |
componentDidMount() { | |
!function () { | |
var t; | |
if (t = window.driftt = window.drift = window.driftt || [], !t.init) return t.invoked ? void (window.console && console.error && console.error("Drift snippet included twice.")) : (t.invoked = !0, | |
t.methods = ["identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on"], | |
t.factory = function (e) { | |
return function () { | |
var n; | |
return n = Array.prototype.slice.call(arguments), n.unshift(e), t.push(n), t; | |
}; | |
}, t.methods.forEach(function (e) { | |
t[e] = t.factory(e); | |
}), t.load = function (t) { | |
var e, n, o, i; | |
e = 3e5, i = Math.ceil(new Date() / e) * e, o = document.createElement("script"), | |
o.type = "text/javascript", o.async = !0, o.crossorigin = "anonymous", o.src = "https://js.driftt.com/include/" + i + "/" + t + ".js", | |
n = document.getElementsByTagName("script")[0], n.parentNode.insertBefore(o, n); | |
}); | |
}(); | |
drift.SNIPPET_VERSION = '0.3.1'; | |
drift.load('YOUR_DRIFT_TOKEN'); | |
this.updateUserIdentity(); | |
} | |
componentDidUpdate() { | |
this.updateUserIdentity(); | |
} | |
render() { | |
return ( | |
<div></div> | |
); | |
} | |
updateUserIdentity() { | |
if (!this.props.authUser || !this.props.authUser.userId) { | |
drift.identify(0, {}); | |
return; | |
} | |
console.log("CustomerSupportManager :: updateUserIdentity :: activated"); | |
// Additional attributes documented @ https://help.drift.com/developer-docs/javascript-sdk | |
drift.identify(this.props.authUser.userID, { | |
name: this.props.authUser.userName, | |
email: this.props.authUser.userEmail, | |
startDate: this.props.authUser.dateJoined.getTime(), | |
revenue: this.props.tokensPurchased, | |
}); | |
} | |
} | |
export function mapStateToProps(state) { | |
return { | |
// debugMode: state.prefs.debug, | |
authUser: state.auth.user, | |
tokensPurchased: state.user.billing.data.tokensPurchased, | |
}; | |
} | |
export default connect( | |
mapStateToProps, | |
)(CustomerSupportManager); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment