utm tracking in db (#574)

* utm tracking in db

* fix array key bug
This commit is contained in:
Favour Olayinka 2024-09-18 17:50:04 +01:00 committed by GitHub
parent 7f6c21408c
commit a057045ef6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 44 additions and 1 deletions

View File

@ -53,6 +53,7 @@ class OAuthController extends Controller
"message" => "OAuth service failed to authenticate: " . $e->getMessage()
]);
}
$user = $this->findOrCreateUser($provider, $driverUser);
if (!$user) {
@ -116,6 +117,7 @@ class OAuthController extends Controller
'name' => $socialiteUser->getName(),
'email' => $email,
'email_verified_at' => now(),
'utm_data' => json_decode(request()->utm_data, true)
]);
// Create and sync workspace

View File

@ -64,6 +64,7 @@ class RegisterController extends Controller
'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.',
]);
@ -82,6 +83,7 @@ class RegisterController extends Controller
'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

View File

@ -32,6 +32,7 @@ class User extends Authenticatable implements JWTSubject
'email',
'password',
'hear_about_us',
'utm_data',
];
/**
@ -54,6 +55,7 @@ class User extends Authenticatable implements JWTSubject
{
return [
'email_verified_at' => 'datetime',
'utm_data' => 'array',
];
}

View File

@ -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');
});
}
};

View File

@ -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
}
},
@ -157,6 +159,7 @@ export default {
password_confirmation: "",
agree_terms: false,
appsumo_license: null,
utm_data: null
}),
disableEmail:false
}),
@ -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")

View File

@ -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: {

View File

@ -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",

View File

@ -30,6 +30,9 @@
</template>
<script setup>
import { useNuxtApp } from "nuxt/app";
const { $utm } = useNuxtApp();
const router = useRouter()
const route = useRoute()
const authStore = useAuthStore()
@ -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)