Integration with Segment
What You'll Need
Prerequisites for the app
Frontend
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="google-signin-client_id">
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>
<script>
function onSignIn(googleUser) {
// Useful data for your client-side scripts:
var profile = googleUser.getBasicProfile();
var xhttp = new XMLHttpRequest();
var id = profile.getId();
var name = profile.getName();
var email = profile.getEmail();
var details = {
id: id.toString(),
name: name.toString(),
email: email.toString()
}
console.log("det:"+JSON.stringify(details));
xhttp.open("POST", "URL of Endpoint comes here", true);
xhttp.send(JSON.stringify(details));
console.log("ID: " + profile.getId()); // Don't send this directly to your server!
console.log('Full Name: ' + profile.getName());
console.log('Given Name: ' + profile.getGivenName());
console.log('Family Name: ' + profile.getFamilyName());
console.log("Image URL: " + profile.getImageUrl());
console.log("Email: " + profile.getEmail());
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
console.log("ID Token: " + id_token);
};
</script>
<a href="#" onclick="signOut();">Sign out</a>
<script>
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
</script>
</body>
</html>Backend
Identify method
Track method
Page method
Group method
Last updated