mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
create source
This commit is contained in:
1 parent
654f446451
commit
7ada3ca62a
3 files changed
+50
-22
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import type { Client } from '@appwrite.io/console';
|
||||
|
||||
export class Sources {
|
||||
client: Client;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
async create(
|
||||
ref: string,
|
||||
referrer: string,
|
||||
utmSource: string,
|
||||
utmCampaign: string,
|
||||
utmMedium: string,
|
||||
): Promise<any> {
|
||||
const path = `/console/sources`;
|
||||
const params = {
|
||||
ref,
|
||||
referrer,
|
||||
utmSource,
|
||||
utmCampaign,
|
||||
utmMedium,
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'POST',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
Vcs
|
||||
} from '@appwrite.io/console';
|
||||
import { Billing } from '../sdk/billing';
|
||||
import { Sources } from '$lib/sdk/sources';
|
||||
|
||||
const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`;
|
||||
|
||||
@@ -70,7 +71,8 @@ export const sdk = {
|
||||
migrations: new Migrations(clientConsole),
|
||||
console: new Console(clientConsole),
|
||||
assistant: new Assistant(clientConsole),
|
||||
billing: new Billing(clientConsole)
|
||||
billing: new Billing(clientConsole),
|
||||
sources: new Sources(clientConsole),
|
||||
},
|
||||
get forProject() {
|
||||
const projectId = getProjectId();
|
||||
|
||||
+12
-21
@@ -16,7 +16,7 @@
|
||||
import { loading, requestedMigration } from './store';
|
||||
import { parseIfString } from '$lib/helpers/object';
|
||||
import Consent from '$lib/components/consent.svelte';
|
||||
import Cookies from 'js-cookie';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
|
||||
if (browser) {
|
||||
window.VERCEL_ANALYTICS_ID = import.meta.env.VERCEL_ANALYTICS_ID?.toString() ?? false;
|
||||
@@ -25,30 +25,21 @@
|
||||
onMount(async () => {
|
||||
// handle sources
|
||||
if (browser) {
|
||||
let currentSources = [];
|
||||
const urlParams = $page.url.searchParams;
|
||||
const ref = urlParams.get('ref');
|
||||
const utm_source = urlParams.get('utm_source');
|
||||
const utm_medium = urlParams.get('utm_medium');
|
||||
const utm_campaign = urlParams.get('utm_campaign');
|
||||
const utmSource = urlParams.get('utm_source');
|
||||
const utmMedium = urlParams.get('utm_medium');
|
||||
const utmCampaign = urlParams.get('utm_campaign');
|
||||
const referrer = document.referrer;
|
||||
|
||||
// Aggregate and display sources from URL parameters
|
||||
if (ref) currentSources.push(`ref=${ref}`);
|
||||
if (utm_source) currentSources.push(`utm_source=${utm_source}`);
|
||||
if (utm_medium) currentSources.push(`utm_medium=${utm_medium}`);
|
||||
if (utm_campaign) currentSources.push(`utm_campaign=${utm_campaign}`);
|
||||
if (referrer) currentSources.push(`referrer=${referrer}`);
|
||||
|
||||
if (currentSources.length) {
|
||||
let currentSource = currentSources.join(';');
|
||||
const source = Cookies.get('source');
|
||||
let sources = source ? decodeURIComponent(source).split(',') : [];
|
||||
sources.push(currentSource);
|
||||
if(sources.length > 50) {
|
||||
sources.shift();
|
||||
}
|
||||
Cookies.set('source', sources, { domain: '.appwrite.io' });
|
||||
if (ref || referrer || utmSource || utmCampaign || utmMedium) {
|
||||
await sdk.forConsole.sources.create(
|
||||
ref,
|
||||
referrer,
|
||||
utmSource,
|
||||
utmCampaign,
|
||||
utmMedium
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user