From db91da19bd59d41fd94381390d596365d3a68402 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Thu, 27 Jul 2023 15:42:44 +0800 Subject: [PATCH] feat(console): report LinkedIn conversion (#4251) * feat(console): report linkedin conversion * refactor(console): clean up code --- .../src/components/ReportConversion/index.tsx | 57 +++++++++++++++++++ .../src/components/ReportConversion/utils.ts | 44 ++++++++++++++ packages/console/src/include.d/gtag.d.ts | 3 - packages/console/src/include.d/tags.d.ts | 9 +++ .../console/src/onboarding/constants/index.ts | 4 -- packages/console/src/onboarding/index.tsx | 41 +------------ packages/console/src/onboarding/utils.ts | 12 ---- 7 files changed, 113 insertions(+), 57 deletions(-) create mode 100644 packages/console/src/components/ReportConversion/index.tsx create mode 100644 packages/console/src/components/ReportConversion/utils.ts delete mode 100644 packages/console/src/include.d/gtag.d.ts create mode 100644 packages/console/src/include.d/tags.d.ts delete mode 100644 packages/console/src/onboarding/constants/index.ts diff --git a/packages/console/src/components/ReportConversion/index.tsx b/packages/console/src/components/ReportConversion/index.tsx new file mode 100644 index 000000000..2ed523127 --- /dev/null +++ b/packages/console/src/components/ReportConversion/index.tsx @@ -0,0 +1,57 @@ +import { useEffect } from 'react'; +import { Helmet } from 'react-helmet'; + +import { + shouldReport, + lintrk, + gtagAwTrackingId, + linkedInConversionId, + gtag, + gtagSignUpConversionId, +} from './utils'; + +/** + * In cloud production environment, this component initiates gtag.js and LinkedIn + * Insight Tag, then reports a sign-up conversion to them. + */ +export default function ReportConversion() { + /** + * This `useEffect()` initiates Google Tag and report a sign-up conversion to it. + * It may run multiple times (e.g. a user visit multiple times to finish the onboarding process, + * which rarely happens), but it'll be okay since we've set conversion's "Count" to "One" + * which means only the first interaction is valuable. + * + * Track this conversion in the backend has been considered, but Google does not provide + * a clear guideline for it and marks the [Node library](https://developers.google.com/tag-platform/tag-manager/api/v2/libraries) + * as "alpha" which looks unreliable. + */ + useEffect(() => { + if (shouldReport) { + gtag('js', new Date()); + gtag('config', gtagAwTrackingId); + gtag('event', 'conversion', { + send_to: gtagSignUpConversionId, + }); + + lintrk('track', { conversion_id: linkedInConversionId }); + console.debug('Have a good day!'); + } else { + console.debug("Not reporting conversion because it's not production"); + } + }, []); + + if (shouldReport) { + return ( + +