How do I install a Google Analytics signup event upon signup?

I am trying to put a Google Analytics signup event behind the authentication moment, has anyone done this before?
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Ricardo Batista. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain specific information about integrating Google Analytics signup event upon signup in Wasp. However, you can customize the signup process in Wasp and add your custom code after the signup. Here is an example of how you can customize the signup process:
// main.wasp
action customSignup {
fn: import { signup } from "@src/auth/signup.js",
}

// src/auth/signup.js
import {
ensurePasswordIsPresent,
ensureValidPassword,
ensureValidUsername,
createProviderId,
sanitizeAndSerializeProviderData,
createUser,
} from 'wasp/server/auth'

export const signup = async (args, _context) => {
ensureValidUsername(args)
ensurePasswordIsPresent(args)
ensureValidPassword(args)

try {
const providerId = createProviderId('username', args.username)
const providerData = await sanitizeAndSerializeProviderData({
hashedPassword: args.password,
})

await createUser(
providerId,
providerData,
// Any additional data you want to store on the User entity
{},
)
} catch (e) {
return {
success: false,
message: e.message,
}
}

// Your custom code after sign-up.
// ...

return {
success: true,
message: 'User created successfully',
}
}
// main.wasp
action customSignup {
fn: import { signup } from "@src/auth/signup.js",
}

// src/auth/signup.js
import {
ensurePasswordIsPresent,
ensureValidPassword,
ensureValidUsername,
createProviderId,
sanitizeAndSerializeProviderData,
createUser,
} from 'wasp/server/auth'

export const signup = async (args, _context) => {
ensureValidUsername(args)
ensurePasswordIsPresent(args)
ensureValidPassword(args)

try {
const providerId = createProviderId('username', args.username)
const providerData = await sanitizeAndSerializeProviderData({
hashedPassword: args.password,
})

await createUser(
providerId,
providerData,
// Any additional data you want to store on the User entity
{},
)
} catch (e) {
return {
success: false,
message: e.message,
}
}

// Your custom code after sign-up.
// ...

return {
success: true,
message: 'User created successfully',
}
}
You can add your Google Analytics signup event in the "Your custom code after sign-up" section. For more details, you can refer to the Wasp documentation (https://wasp-lang.dev/docs/auth/username-and-pass#2-creating-your-custom-sign-up-action). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Ricardo Batista, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho3mo ago
Since Wasp 0.14, we added some new Auth Hooks, one of them being onAfterSignup: https://wasp-lang.dev/docs/auth/auth-hooks#executing-code-after-the-user-signs-up It allows you to execute code after the signup, that should probably work for you.
Auth Hooks | Wasp
Auth hooks allow you to "hook into" the auth process at various stages and run your custom code. For example, if you want to forbid certain emails from signing up, or if you wish to send a welcome email to the user after they sign up, auth hooks are the way to go.
Want results from more Discord servers?
Add your server