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

Pre-bundled Script tag for visual editor #1773

Merged
merged 10 commits into from Oct 25, 2023
Merged

Pre-bundled Script tag for visual editor #1773

merged 10 commits into from Oct 25, 2023

Conversation

jdorn
Copy link
Member

@jdorn jdorn commented Oct 20, 2023

Features and Changes

Thin wrapper around our javascript SDK for easier visual editor integration through GTM or other low-code tools.

TODO:

  • Bump Javascript SDK version and release on npm

Basic Usage

<script
  src="https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/auto.min.js"
  data-client-key="sdk-abc123"
></script>

This will instantiate a GrowthBook instance and call loadFeatures(), kicking off any visual editor experiments.

Default Attributes

The following attributes are set automatically:

  • id - creates a long-lived gbuuid cookie if it doesn't exist already
  • url
  • path
  • host
  • query
  • deviceType - either mobile or desktop
  • browser - one of chrome, edge, firefox, safari, or unknown
  • utmSource
  • utmMedium
  • utmCampaign
  • utmTerm
  • utmContent

The UTM attributes are persisted in session storage so they will continue to be set even after page loads.

Default Tracking Callback

A default trackingCallback function will be set that fires both analytics.track (Segment) and dataLayer.push (GA4/GTM) events with the recommended event/property names.

URL Updating

We will poll the page every 500ms to check for URL changes. If detected, it will call gb.setURL() and update any URL-related attributes.

This is critical for SPAs since it allows visual editor experiments to reset and take effect automatically.

Customizing

In addition to passing context settings in data-* attributes, you can also define a window.growthbook_config object. This is useful for overriding non-string options like trackingCallback or attributes. You can mix and match the two as well:

<script>
window.growthbook_config={
  trackingCallback: (experiment, result) => {
    console.log(experiment, result);
  }
}
</script>
<script
  src="https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/auto.min.js"
  data-client-key="sdk-abc123"
></script>

@github-actions
Copy link

github-actions bot commented Oct 20, 2023

Your preview environment pr-1773-bttf has been deployed.

Preview environment endpoints are available at:

@bttf bttf self-requested a review October 20, 2023 16:12
@github-actions
Copy link

github-actions bot commented Oct 23, 2023

Deploy preview for docs ready!

✅ Preview
https://docs-gd2xoof7h-growthbook.vercel.app

Built with commit 32c1e80.
This pull request is being automatically deployed with vercel-action

@jdorn jdorn marked this pull request as ready for review October 24, 2023 00:12
Copy link
Collaborator

@bttf bttf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks solid, just one comment regarding documentation

docs/docs/visual-editor.mdx Show resolved Hide resolved
@jdorn jdorn merged commit 26fb00f into main Oct 25, 2023
6 checks passed
@jdorn jdorn deleted the sdk-auto-script branch October 25, 2023 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants