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

View File

@ -64,6 +64,7 @@ class RegisterController extends Controller
'agree_terms' => ['required', Rule::in([true])], 'agree_terms' => ['required', Rule::in([true])],
'appsumo_license' => ['nullable'], 'appsumo_license' => ['nullable'],
'invite_token' => ['nullable', 'string'], 'invite_token' => ['nullable', 'string'],
'utm_data' => ['nullable', 'array']
], [ ], [
'agree_terms' => 'Please agree with the terms and conditions.', 'agree_terms' => 'Please agree with the terms and conditions.',
]); ]);
@ -82,6 +83,7 @@ class RegisterController extends Controller
'email' => strtolower($data['email']), 'email' => strtolower($data['email']),
'password' => bcrypt($data['password']), 'password' => bcrypt($data['password']),
'hear_about_us' => $data['hear_about_us'], 'hear_about_us' => $data['hear_about_us'],
'utm_data' => array_key_exists('utm_data', $data) ? $data['utm_data'] : null,
]); ]);
// Add relation with user // Add relation with user

View File

@ -32,6 +32,7 @@ class User extends Authenticatable implements JWTSubject
'email', 'email',
'password', 'password',
'hear_about_us', 'hear_about_us',
'utm_data',
]; ];
/** /**
@ -54,6 +55,7 @@ class User extends Authenticatable implements JWTSubject
{ {
return [ return [
'email_verified_at' => 'datetime', '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'], emits: ['afterQuickLogin', 'openLogin'],
setup() { setup() {
const { $utm } = useNuxtApp()
return { return {
authStore: useAuthStore(), authStore: useAuthStore(),
formsStore: useFormsStore(), formsStore: useFormsStore(),
workspaceStore: useWorkspacesStore(), workspaceStore: useWorkspacesStore(),
providersStore: useOAuthProvidersStore(), providersStore: useOAuthProvidersStore(),
logEvent: useAmplitude().logEvent, logEvent: useAmplitude().logEvent,
$utm
} }
}, },
@ -157,6 +159,7 @@ export default {
password_confirmation: "", password_confirmation: "",
agree_terms: false, agree_terms: false,
appsumo_license: null, appsumo_license: null,
utm_data: null
}), }),
disableEmail:false disableEmail:false
}), }),
@ -204,6 +207,7 @@ export default {
methods: { methods: {
async register() { async register() {
let data let data
this.form.utm_data = this.$utm.value
try { try {
// Register the user. // Register the user.
data = await this.form.post("/register") data = await this.form.post("/register")

View File

@ -14,6 +14,7 @@ export default defineNuxtConfig({
'@vueuse/motion/nuxt', '@vueuse/motion/nuxt',
'nuxt-simple-sitemap', 'nuxt-simple-sitemap',
'@nuxt/ui', '@nuxt/ui',
'nuxt-utm',
...process.env.NUXT_PUBLIC_GTM_CODE ? ['@zadigetvoltaire/nuxt-gtm'] : [], ...process.env.NUXT_PUBLIC_GTM_CODE ? ['@zadigetvoltaire/nuxt-gtm'] : [],
], ],
build: { build: {

View File

@ -23,6 +23,7 @@
"nuxt": "^3.9.1", "nuxt": "^3.9.1",
"nuxt-icon": "^0.6.10", "nuxt-icon": "^0.6.10",
"nuxt-simple-sitemap": "^4.2.3", "nuxt-simple-sitemap": "^4.2.3",
"nuxt-utm": "^0.1.10",
"postcss": "^8.4.32", "postcss": "^8.4.32",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"sass": "^1.69.6", "sass": "^1.69.6",

View File

@ -30,6 +30,9 @@
</template> </template>
<script setup> <script setup>
import { useNuxtApp } from "nuxt/app";
const { $utm } = useNuxtApp();
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()
const authStore = useAuthStore() const authStore = useAuthStore()
@ -49,7 +52,8 @@ function handleCallback() {
opnFetch(`/oauth/${provider}/callback`, { opnFetch(`/oauth/${provider}/callback`, {
method: 'POST', method: 'POST',
params: { params: {
code code,
utm_data: $utm.value
} }
}).then(async (data) => { }).then(async (data) => {
authStore.setToken(data.token) authStore.setToken(data.token)