Skip to content
Open
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 apps/webapp/app/components/icon-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Gmail } from "./icons/gmail";
import { GoogleCalendar } from "./icons/google-calendar";
import { GoogleSheets } from "./icons/google-sheets";
import { GoogleDocs } from "./icons/google-docs";
import { GoogleAnalytics } from "./icons/google-analytics";
import { GoogleSearchConsole } from "./icons/google-search-console";
import { CalCom } from "./icons/cal_com";
import { Notion } from "./icons/notion";
Expand Down Expand Up @@ -55,6 +56,7 @@ export const ICON_MAPPING = {
"google-calendar": GoogleCalendar,
"google-sheets": GoogleSheets,
"google-docs": GoogleDocs,
"google-analytics": GoogleAnalytics,
"google-search-console": GoogleSearchConsole,
linear: LinearIcon,
cursor: Cursor,
Expand Down
28 changes: 28 additions & 0 deletions apps/webapp/app/components/icons/google-analytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { IconProps } from './types.tsx';

/**
* Google Analytics 4 icon — simplified bar-chart / GA "G" mark in orange.
*/
export function GoogleAnalytics({ size = 18, className }: IconProps) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 48 48"
width={size}
height={size}
className={className}
aria-label="Google Analytics"
>
{/* Background circle */}
<circle cx="24" cy="24" r="22" fill="#E8710A" />

{/* Bar chart — three rising bars (white) */}
{/* Left bar (short) */}
<rect x="9" y="30" width="8" height="10" rx="2" fill="#fff" />
{/* Middle bar (medium) */}
<rect x="20" y="22" width="8" height="18" rx="2" fill="#fff" />
{/* Right bar (tall) */}
<rect x="31" y="13" width="8" height="27" rx="2" fill="#fff" />
</svg>
);
}
65 changes: 65 additions & 0 deletions integrations/google-analytics/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import js from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import importPlugin from 'eslint-plugin-import';
import eslintPluginPrettier from 'eslint-plugin-prettier';
import unusedImports from 'eslint-plugin-unused-imports';
import typescriptEslint from 'typescript-eslint';

export default [
js.configs.recommended,
...typescriptEslint.configs.recommended,
eslintConfigPrettier,
{
files: ['**/*.{js,mjs,cjs,ts,jsx,tsx}'],
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
globals: {
console: 'readonly',
process: 'readonly',
Buffer: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
global: 'readonly',
},
},
plugins: {
import: importPlugin,
prettier: eslintPluginPrettier,
'unused-imports': unusedImports,
},
rules: {
'prettier/prettier': 'error',
'no-unused-vars': 'off',
'unused-imports/no-unused-imports': 'error',
'unused-imports/no-unused-vars': [
'warn',
{
vars: 'all',
varsIgnorePattern: '^_',
args: 'after-used',
argsIgnorePattern: '^_',
},
],
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'always',
},
],
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'warn',
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
},
];
59 changes: 59 additions & 0 deletions integrations/google-analytics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "@core/google-analytics",
"version": "0.1.0",
"description": "Google Analytics 4 integration for CORE",
"main": "./bin/index.js",
"module": "./bin/index.mjs",
"type": "module",
"files": [
"google-analytics",
"bin"
],
"bin": {
"google-analytics": "./bin/index.js"
},
"exports": {
"./frontend": {
"import": "./dist/frontend.js"
},
"./package.json": "./package.json"
},
"scripts": {
"build": "pnpm run build:cli && pnpm run build:frontend",
"build:cli": "rimraf bin && bun build src/index.ts --outfile bin/index.js --target node --minify",
"build:frontend": "tsup",
"dev:frontend": "tsup --watch",
"lint": "eslint --ext js,ts,tsx src/ --fix",
"prettier": "prettier --config .prettierrc --write ."
},
"devDependencies": {
"@babel/preset-typescript": "^7.26.0",
"@types/node": "^18.0.20",
"@types/react": "^19.2.13",
"eslint": "^9.24.0",
"eslint-config-prettier": "^10.1.2",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-unused-imports": "^2.0.0",
"google-auth-library": "10.5.0",
"googleapis": "166.0.0",
"prettier": "^3.4.2",
"react": "^19.2.4",
"rimraf": "^3.0.2",
"tslib": "^2.8.1",
"tsup": "^8.0.1",
"typescript": "^4.7.2"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@redplanethq/sdk": "0.1.18",
"axios": "^1.7.9",
"commander": "^12.0.0",
"zod": "^3.22.4",
"zod-to-json-schema": "^3.22.4"
}
}
136 changes: 136 additions & 0 deletions integrations/google-analytics/scripts/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* Register (or update) the Google Analytics integration definition in the database.
*
* Usage:
* DATABASE_URL=postgresql://... npx tsx scripts/register.ts
*
* Prerequisites:
* - Run `pnpm build` first so the CLI binary exists at bin/index.js
* - Set the DATABASE_URL environment variable to your Postgres connection string
* - Ensure the Google OAuth 2.0 credentials (Client ID + Secret) exist in the DB
* or supply them via environment variables GOOGLE_ANALYTICS_CLIENT_ID /
* GOOGLE_ANALYTICS_CLIENT_SECRET (the script stores them in the `config` column).
*/

import pg from 'pg';

const { Client } = pg;

const INTEGRATION_NAME = 'Google Analytics';
const INTEGRATION_SLUG = 'google-analytics';
const INTEGRATION_VERSION = '0.1.0';

const spec = {
name: INTEGRATION_NAME,
key: INTEGRATION_SLUG,
description:
'Connect your workspace to Google Analytics 4. Query reports, monitor real-time traffic, explore dimensions and metrics, and receive 6-hour traffic summary activities.',
icon: INTEGRATION_SLUG,
mcp: {
type: 'cli',
},
schedule: {
frequency: '0 */6 * * *',
},
auth: {
OAuth2: {
token_url: 'https://oauth2.googleapis.com/token',
authorization_url: 'https://accounts.google.com/o/oauth2/v2/auth',
scopes: [
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
],
scope_identifier: 'scope',
scope_separator: ' ',
token_params: {
access_type: 'offline',
prompt: 'consent',
},
authorization_params: {
access_type: 'offline',
prompt: 'consent',
},
},
},
toolUISupported: true,
};

async function main() {
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
console.error('DATABASE_URL environment variable is required');
process.exit(1);
}

const client = new Client({ connectionString });

// OAuth credentials are stored in the `config` column.
// Provide them via env vars or leave empty and update them via the admin UI later.
const config = {
clientId: process.env.GOOGLE_ANALYTICS_CLIENT_ID ?? '',
clientSecret: process.env.GOOGLE_ANALYTICS_CLIENT_SECRET ?? '',
};

// Path to the compiled CLI binary, relative to the webapp root.
// Adjust this path if you use a different deploy layout.
const binaryUrl = '../../integrations/google-analytics/bin/index.js';

// Frontend bundle URL (served statically or from the package).
const frontendUrl = '../../integrations/google-analytics/dist/frontend.js';

try {
await client.connect();

const result = await client.query(
`
INSERT INTO core."IntegrationDefinitionV2"
("id", "name", "slug", "description", "icon", "spec", "config", "version", "url", "frontendUrl", "updatedAt", "createdAt")
VALUES
(gen_random_uuid(), $1, $2, $3, $4, $5, $6, $7, $8, $9, NOW(), NOW())
ON CONFLICT (name) DO UPDATE SET
"slug" = EXCLUDED."slug",
"description" = EXCLUDED."description",
"icon" = EXCLUDED."icon",
"spec" = EXCLUDED."spec",
"config" = EXCLUDED."config",
"version" = EXCLUDED."version",
"url" = EXCLUDED."url",
"frontendUrl" = EXCLUDED."frontendUrl",
"updatedAt" = NOW()
RETURNING id, name, slug, version;
`,
[
INTEGRATION_NAME,
INTEGRATION_SLUG,
spec.description,
INTEGRATION_SLUG, // icon key matches ICON_MAPPING
JSON.stringify(spec),
JSON.stringify(config),
INTEGRATION_VERSION,
binaryUrl,
frontendUrl,
]
);

const row = result.rows[0];
console.log(`Google Analytics integration registered successfully:`);
console.log(` id: ${row.id}`);
console.log(` slug: ${row.slug}`);
console.log(` version: ${row.version}`);

if (!config.clientId || !config.clientSecret) {
console.warn(
'\nWarning: GOOGLE_ANALYTICS_CLIENT_ID / GOOGLE_ANALYTICS_CLIENT_SECRET are not set.\n' +
'Update the `config` column in IntegrationDefinitionV2 with your OAuth credentials before users connect.'
);
}
} catch (error) {
console.error('Error registering Google Analytics integration:', error);
process.exit(1);
} finally {
await client.end();
}
}

main().catch(console.error);
Loading