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

feat: add analytics for handoff checklist #2413

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
35 changes: 35 additions & 0 deletions packages/widget-figma-dev-handoff-checklist/build-dev-handoff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const esbuild = require('esbuild');
require('dotenv').config();

async function build() {
// Check if the `--watch` argument is passed in the command line
const isWatchMode = process.argv.includes('--watch');

// Create the build context
const ctx = await esbuild.context({
entryPoints: ['dev-handoff-checklist/code.tsx'],
bundle: true,
outfile: 'dev-handoff-checklist/dist/code.js',
target: 'es6',
define: {
'process.env.SEGMENT_WRITE_KEY': JSON.stringify(btoa(process.env.SEGMENT_WRITE_KEY ?? '')),
},
});

if (isWatchMode) {
// Enable watch mode
await ctx.watch();
console.log('Watching for changes...');
} else {
// Perform a single build
await ctx.rebuild();
console.log('Build completed.');
await ctx.dispose();
}
}

// Execute the build function
build().catch((error) => {
console.error(error);
process.exit(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const esbuild = require('esbuild');
require('dotenv').config();

async function build() {
// Check if the `--watch` argument is passed in the command line
const isWatchMode = process.argv.includes('--watch');

// Create the build context
const ctx = await esbuild.context({
entryPoints: ['snowflake-handoff-checklist/code.tsx'],
bundle: true,
outfile: 'snowflake-handoff-checklist/dist/code.js',
target: 'es6',
define: {
'process.env.SEGMENT_WRITE_KEY': JSON.stringify(btoa(process.env.SEGMENT_WRITE_KEY ?? '')),
},
});

if (isWatchMode) {
// Enable watch mode
await ctx.watch();
console.log('Watching for changes...');
} else {
// Perform a single build
await ctx.rebuild();
console.log('Build completed.');
await ctx.dispose();
}
}

// Execute the build function
build().catch((error) => {
console.error(error);
process.exit(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@
import Checkbox from '../components/Checkbox';
import SectionHeader from '../components/SectionHeader';
import ProgressBar from '../components/ProgressBar';
const { AutoLayout, Text, useSyncedState } = figma.widget;
import { sendAnalytics } from '../utils/sendAnalytics';
const { AutoLayout, Text, useSyncedState, useEffect, waitForTask } = figma.widget;

function Widget() {
const [checkedItems, setCheckedItems] = useSyncedState('checkedStates', 0);
const [isAnalyticsLoadEventSent, setIsAnalyticsLoadEventSent] = useSyncedState(
'analytics',
false,
);

useEffect(() => {
if (!isAnalyticsLoadEventSent) {
// send analytics
waitForTask(
sendAnalytics({
eventName: 'Blade Dev Handoff Checklist Used',
}),
);
setIsAnalyticsLoadEventSent(true);
}
});

const updateChecklist = (checkedState: true | false): void => {
if (checkedState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
{
"name": "Dev Handoff Checklist",
"id": "",
"id": "1418629124817655875",
"api": "1.0.0",
"main": "dist/code.js",
"main": "./dist/code.js",
"capabilities": [],
"enableProposedApi": false,
"documentAccess": "dynamic-page",
"editorType": ["figma"],
"editorType": [
"figma"
],
"containsWidget": true,
"widgetApi": "1.0.0",
"permissions": [
"currentuser"
],
"networkAccess": {
"allowedDomains": ["none"]
"allowedDomains": [
"https://api.segment.io"
]
}
}
}
16 changes: 13 additions & 3 deletions packages/widget-figma-dev-handoff-checklist/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "Figma Widgets",
"name": "handoff-widget",
"private": true,
"version": "1.0.0",
"description": "Razorpay's official widgets - Figma Widget",
"scripts": {
"build:dev": "esbuild dev-handoff-checklist/code.tsx --bundle --outfile=dev-handoff-checklist/dist/code.js --target=es6",
"build:snowflake": "esbuild snowflake-handoff-checklist/code.tsx --bundle --outfile=snowflake-handoff-checklist/dist/code.js --target=es6",
"build:dev": "node build-dev-handoff.js",
"build:snowflake": "node build-snowflake-handoff.js",
"watch:dev": "npm run build:dev -- --watch",
"watch:snowflake": "npm run build:snowflake -- --watch",
"lint": "eslint --ext .ts,.tsx --ignore-pattern node_modules .",
Expand All @@ -14,12 +14,22 @@
},
"author": "",
"license": "",
"dependencies": {
"@create-figma-plugin/utilities": "2.5.0",
"dotenv": "16.3.1",
"fs": "0.0.1-security",
"path": "0.12.7"
},
"devDependencies": {
"@figma/eslint-plugin-figma-plugins": "0.15.0",
"@figma/plugin-typings": "1.100.2",
"@figma/widget-typings": "1.9.2",
"@segment/analytics-next": "1.53.0",
"@types/node": "22.9.0",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"cross-env": "7.0.3",
"dotenv-cli": "7.4.2",
"esbuild": "0.24.0",
"eslint": "^8.54.0",
"typescript": "^5.3.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@
import Checkbox from '../components/Checkbox';
import SectionHeader from '../components/SectionHeader';
import ProgressBar from '../components/ProgressBar';
const { AutoLayout, Text, useSyncedState } = figma.widget;
import { sendAnalytics } from '../utils/sendAnalytics';
const { AutoLayout, Text, useSyncedState, useEffect, waitForTask } = figma.widget;

function Widget() {
const [checkedItems, setCheckedItems] = useSyncedState('checkedStates', 0);
const [isAnalyticsLoadEventSent, setIsAnalyticsLoadEventSent] = useSyncedState(
'analytics',
false,
);

useEffect(() => {
if (!isAnalyticsLoadEventSent) {
// send analytics
waitForTask(
sendAnalytics({
eventName: 'Blade Snowflake Handoff Checklist Used',
}),
);
setIsAnalyticsLoadEventSent(true);
}
});

const updateChecklist = (checkedState: true | false): void => {
if (checkedState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Snowflake Handoff Checklist",
"id": "",
"id": "1428702173901973283",
"api": "1.0.0",
"main": "dist/code.js",
"capabilities": [],
Expand All @@ -9,7 +9,12 @@
"editorType": ["figma"],
"containsWidget": true,
"widgetApi": "1.0.0",
"permissions": [
"currentuser"
],
"networkAccess": {
"allowedDomains": ["none"]
"allowedDomains": [
"https://api.segment.io"
]
}
}
7 changes: 4 additions & 3 deletions packages/widget-figma-dev-handoff-checklist/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"moduleResolution": "Node",
"strict": true,
"skipLibCheck": true,
"typeRoots": ["./node_modules/@figma", "./node_modules/@types"],
"target": "ESNext"
}
"typeRoots": ["node_modules/@figma", "node_modules/@types"],
"target": "ESNext",
},
"include": ["./**/*.tsx", "./**/*.tsx"]
}
29 changes: 29 additions & 0 deletions packages/widget-figma-dev-handoff-checklist/utils/sendAnalytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { incrementTotalUseCountAsync } from '@create-figma-plugin/utilities';

export const sendAnalytics = async ({
eventName,
properties,
}: {
eventName: string;
properties?: object;
}): Promise<void> => {
const pluginUsageCount = await incrementTotalUseCountAsync();
await fetch('https://api.segment.io/v1/track', {
method: 'POST',
headers: {
'content-type': 'application/json',
Authorization: `Basic ${process.env.SEGMENT_WRITE_KEY}`,
},
body: JSON.stringify({
userId: figma.currentUser?.id ?? `logged-out-user-${Date.now()}`,
event: eventName,
properties: {
userName: figma.currentUser?.name,
fileName: figma.root.name,
pageName: figma.currentPage.name,
pluginUsageCount,
...properties,
},
}),
});
};
Loading
Loading