Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utm tracking in db #574

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/app/Http/Controllers/Auth/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function handleCallback(OAuthProviderService $provider)
"message" => "OAuth service failed to authenticate: " . $e->getMessage()
]);
}

$user = $this->findOrCreateUser($provider, $driverUser);

if (!$user) {
Expand Down Expand Up @@ -116,6 +117,7 @@ protected function findOrCreateUser($provider, $socialiteUser)
'name' => $socialiteUser->getName(),
'email' => $email,
'email_verified_at' => now(),
'utm_data' => json_decode(request()->utm_data, true)
]);

// Create and sync workspace
Expand Down
2 changes: 2 additions & 0 deletions api/app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected function validator(array $data)
'agree_terms' => ['required', Rule::in([true])],
'appsumo_license' => ['nullable'],
'invite_token' => ['nullable', 'string'],
'utm_data' => ['nullable', 'array']
], [
'agree_terms' => 'Please agree with the terms and conditions.',
]);
Expand All @@ -82,6 +83,7 @@ protected function create(array $data)
'email' => strtolower($data['email']),
'password' => bcrypt($data['password']),
'hear_about_us' => $data['hear_about_us'],
'utm_data' => array_key_exists('utm_data', $data) ? $data['utm_data'] : null,
]);

// Add relation with user
Expand Down
2 changes: 2 additions & 0 deletions api/app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class User extends Authenticatable implements JWTSubject
'email',
'password',
'hear_about_us',
'utm_data',
];

/**
Expand All @@ -54,6 +55,7 @@ protected function casts()
{
return [
'email_verified_at' => 'datetime',
'utm_data' => 'array',
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->json('utm_data')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('utm_data');
});
}
};
4 changes: 4 additions & 0 deletions client/components/pages/auth/components/RegisterForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ export default {
emits: ['afterQuickLogin', 'openLogin'],

setup() {
const { $utm } = useNuxtApp()
return {
authStore: useAuthStore(),
formsStore: useFormsStore(),
workspaceStore: useWorkspacesStore(),
providersStore: useOAuthProvidersStore(),
logEvent: useAmplitude().logEvent,
$utm
}
},

Expand All @@ -157,6 +159,7 @@ export default {
password_confirmation: "",
agree_terms: false,
appsumo_license: null,
utm_data: null
}),
disableEmail:false
}),
Expand Down Expand Up @@ -204,6 +207,7 @@ export default {
methods: {
async register() {
let data
this.form.utm_data = this.$utm.value
try {
// Register the user.
data = await this.form.post("/register")
Expand Down
1 change: 1 addition & 0 deletions client/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineNuxtConfig({
'@vueuse/motion/nuxt',
'nuxt-simple-sitemap',
'@nuxt/ui',
'nuxt-utm',
...process.env.NUXT_PUBLIC_GTM_CODE ? ['@zadigetvoltaire/nuxt-gtm'] : [],
],
build: {
Expand Down
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"nuxt": "^3.9.1",
"nuxt-icon": "^0.6.10",
"nuxt-simple-sitemap": "^4.2.3",
"nuxt-utm": "^0.1.10",
"postcss": "^8.4.32",
"prettier": "^3.2.5",
"sass": "^1.69.6",
Expand Down
6 changes: 5 additions & 1 deletion client/pages/oauth/callback.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
</template>

<script setup>
import { useNuxtApp } from "nuxt/app";

const { $utm } = useNuxtApp();
const router = useRouter()
const route = useRoute()
const authStore = useAuthStore()
Expand All @@ -49,7 +52,8 @@ function handleCallback() {
opnFetch(`/oauth/${provider}/callback`, {
method: 'POST',
params: {
code
code,
utm_data: $utm.value
}
}).then(async (data) => {
authStore.setToken(data.token)
Expand Down
Loading