From bee49d304b0afd6dc2aacd97bd9039254e79b6f7 Mon Sep 17 00:00:00 2001 From: Pablo Seibelt Date: Mon, 14 Oct 2024 12:07:56 -0300 Subject: [PATCH 1/2] Replicate changes done on docs repository for Segment consent and growthbook --- themes/default/layouts/partials/head.html | 45 +++++++++---------- themes/default/theme/package.json | 1 + themes/default/theme/src/scss/main.scss | 8 ++-- themes/default/theme/stencil/src/util/util.ts | 28 ++++++++++++ themes/default/theme/yarn.lock | 12 +++++ 5 files changed, 64 insertions(+), 30 deletions(-) diff --git a/themes/default/layouts/partials/head.html b/themes/default/layouts/partials/head.html index 4df914b22b..8b112539c7 100644 --- a/themes/default/layouts/partials/head.html +++ b/themes/default/layouts/partials/head.html @@ -3,6 +3,23 @@ + + + {{ partial "assets" . }} @@ -233,19 +250,6 @@ - - - - - {{- if eq hugo.Environment "production" }} diff --git a/themes/default/theme/package.json b/themes/default/theme/package.json index f79f144d0b..8dc0f35df7 100644 --- a/themes/default/theme/package.json +++ b/themes/default/theme/package.json @@ -9,6 +9,7 @@ "@algolia/autocomplete-plugin-recent-searches": "^1.9.2", "@algolia/autocomplete-plugin-tags": "^1.9.2", "@algolia/autocomplete-theme-classic": "^1.9.2", + "@growthbook/growthbook": "^1.2.1", "@types/marked": "^4.0.8", "algoliasearch": "^4.17.0", "clipboard-polyfill": "^3.0.3", diff --git a/themes/default/theme/src/scss/main.scss b/themes/default/theme/src/scss/main.scss index f3e850c0ef..dc2bc28520 100644 --- a/themes/default/theme/src/scss/main.scss +++ b/themes/default/theme/src/scss/main.scss @@ -369,12 +369,10 @@ section.newsletter-input pulumi-hubspot-form input.hs-input { @apply fixed bottom-0 right-0 left-0 text-black; z-index: 100; - > div:first-child { - @apply w-full px-3; + @apply w-full px-3; - @screen lg { - @apply w-1/3 float-right mb-2 mr-2 rounded-lg shadow-lg overflow-hidden px-4 py-2; - } + @screen lg { + @apply w-1/3 float-left mb-2 mr-2 rounded-lg shadow-lg overflow-hidden px-4 py-2; } div { diff --git a/themes/default/theme/stencil/src/util/util.ts b/themes/default/theme/stencil/src/util/util.ts index 30a88d95db..a839b45801 100644 --- a/themes/default/theme/stencil/src/util/util.ts +++ b/themes/default/theme/stencil/src/util/util.ts @@ -1,4 +1,32 @@ import * as uuid from "uuid"; +import { GrowthBook } from "@growthbook/growthbook"; + +// Initialize GrowthBook +export const gb = new GrowthBook({ + apiHost: "https://cdn.growthbook.io", + clientKey: (window as any).growthbook_sdk_key, + decryptionKey: (window as any).growthbook_decrypt_key, + enableDevMode: (window as any).growthbook_dev_mode, +}); + +gb.init({ streaming: true }); + +// Hook up GrowthBook to analytics when ready +(window as any).analytics.ready(function() { + gb.setTrackingCallback((experiment, result) => { + (window as any).analytics.track("Experiment Viewed", { + experimentId: experiment.key, + variationId: result.key, + }); + }); + + gb.setAttributes({ + // Set Anon/UserId for GB + ...gb.getAttributes(), + id: (window as any).analytics.user().anonymousId(), + userId: (window as any).analytics.user().id(), + }) +}) // Extracts a query string variable from the browser's location. export function getQueryVariable(paramKey: string): string | null { diff --git a/themes/default/theme/yarn.lock b/themes/default/theme/yarn.lock index 63e308ce88..1b8cc257b6 100644 --- a/themes/default/theme/yarn.lock +++ b/themes/default/theme/yarn.lock @@ -197,6 +197,13 @@ dependencies: purgecss "^4.0.3" +"@growthbook/growthbook@^1.2.1": + version "1.2.1" + resolved "https://registry.yarnpkg.com/@growthbook/growthbook/-/growthbook-1.2.1.tgz#efc236afec8aa061d306d72ab1c9fa67697e513e" + integrity sha512-V0of0mGXZ69poOTPoZ8TFkJkPpC9T766NZiJ1qwzwFAl8ZsuunmguC6RP4muri4q5DRPDzf3lRUSWLk0g8bdbw== + dependencies: + dom-mutator "^0.6.0" + "@jridgewell/gen-mapping@^0.3.0": version "0.3.2" resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz#c1aedc61e853f2bb9f5dfe6d4442d3b565b253b9" @@ -974,6 +981,11 @@ dlv@^1.1.3: resolved "https://registry.yarnpkg.com/dlv/-/dlv-1.1.3.tgz#5c198a8a11453596e751494d49874bc7732f2e79" integrity sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA== +dom-mutator@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/dom-mutator/-/dom-mutator-0.6.0.tgz#079d7a4b3e8981a562cd777548b99baab51d65c5" + integrity sha512-iCt9o0aYfXMUkz/43ZOAUFQYotjGB+GNbYJiJdz4TgXkyToXbbRy5S6FbTp72lRBtfpUMwEc1KmpFEU4CZeoNg== + dom-serializer@^1.0.1: version "1.3.2" resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-1.3.2.tgz#6206437d32ceefaec7161803230c7a20bc1b4d91" From 1b5432fa6d969c1b436da4d11d5fd22923a79758 Mon Sep 17 00:00:00 2001 From: Pablo Seibelt Date: Mon, 14 Oct 2024 12:44:59 -0300 Subject: [PATCH 2/2] Replaced shuldrequireconsent for inEU --- themes/default/layouts/partials/head.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/default/layouts/partials/head.html b/themes/default/layouts/partials/head.html index 8b112539c7..71e865aea9 100644 --- a/themes/default/layouts/partials/head.html +++ b/themes/default/layouts/partials/head.html @@ -368,7 +368,7 @@ preferencesDialogContent: preferencesDialogContent, cancelDialogTitle: cancelDialogTitle, cancelDialogContent: cancelDialogContent, - shouldRequireConsent: () => 'true', + shouldRequireConsent: exports.inEU, closeBehavior: exports.inEU() ? "dismiss" : "accept", bannerTextColor: "black", cdnHost: "evs.analytics.pulumi.com",