Skip to content

Commit

Permalink
feat(cli): Send configuration for ga4 and gtm (#5535)
Browse files Browse the repository at this point in the history
* feat: Send configuration for ga4 and gtm

* Update parseDocsConfiguration

* Bump version
  • Loading branch information
rpc333 authored Jan 6, 2025
1 parent c7f0de0 commit 7f7e1ff
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 15 deletions.
44 changes: 44 additions & 0 deletions docs-yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,30 @@
],
"additionalProperties": false
},
"docs.GTMConfig": {
"type": "object",
"properties": {
"container-id": {
"type": "string"
}
},
"required": [
"container-id"
],
"additionalProperties": false
},
"docs.GoogleAnalytics4Config": {
"type": "object",
"properties": {
"measurement-id": {
"type": "string"
}
},
"required": [
"measurement-id"
],
"additionalProperties": false
},
"docs.AnalyticsConfig": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -475,6 +499,26 @@
"type": "null"
}
]
},
"gtm": {
"oneOf": [
{
"$ref": "#/definitions/docs.GTMConfig"
},
{
"type": "null"
}
]
},
"ga4": {
"oneOf": [
{
"$ref": "#/definitions/docs.GoogleAnalytics4Config"
},
{
"type": "null"
}
]
}
},
"additionalProperties": false
Expand Down
16 changes: 8 additions & 8 deletions fern/apis/docs-yml/definition/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ types:
fullstory: optional<FullStoryAnalyticsConfig>
intercom: optional<IntercomConfig>
posthog: optional<PostHogConfig>
# gtm: optional<GTMConfig>
# ga4: optional<GoogleAnalytics4Config>
gtm: optional<GTMConfig>
ga4: optional<GoogleAnalytics4Config>
# amplitude: optional<AmplitudeConfig>
# mixpanel: optional<MixpanelConfig>
# hotjar: optional<HotJarConfig>
Expand Down Expand Up @@ -58,13 +58,13 @@ types:
api-key: string
endpoint: optional<string>

# GTMConfig:
# properties:
# container-id: string
GTMConfig:
properties:
container-id: string

# GoogleAnalytics4Config:
# properties:
# measurement-id: string
GoogleAnalytics4Config:
properties:
measurement-id: string

# AmplitudeConfig:
# properties:
Expand Down
34 changes: 31 additions & 3 deletions fern/pages/docs/integrations/analytics/google.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ subtitle: Add Google Analytics to your Docs with Fern.

Fern supports integrating with both [Google Analytics 4](https://developers.google.com/analytics) and [Google Tag Manager](https://tagmanager.google.com/).

<Tip>
This feature is available on the Fern Basic plan and above. Reach out to [[email protected]](mailto:[email protected]) to set up your Google Analytics.
</Tip>
## Google Analytics 4

To integrate Google Analytics 4, you'll need a Google Analytics 4 property ID. It should look like: “UA-XXXXXX-X” or "G-XXXXXXX."

### Integrate Google Analytics 4 with your Docs

In your `docs.yml` file, add your Google Analytics 4 property ID under the `measurement-id` key:

<CodeBlock title="docs.yml">
```yaml
analytics:
ga4:
measurement-id: ${GA4_MEASUREMENT_ID} # scans environment variable
```
</CodeBlock>
## Google Tag Manager
To integrate Google Tag Manager, you'll need a Google Tag Manager container ID. It should look like: "GTM-XXXXXX."
### Integrate Google Tag Manager with your Docs
In your `docs.yml` file, add your Google Tag Manager container ID:

<CodeBlock title="docs.yml">
```yaml
analytics:
gtm:
container-id: ${GTM_CONTAINER_ID} # scans environment variable
```
</CodeBlock>
7 changes: 7 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- changelogEntry:
- summary: |
Support configuration of Google Analytics and Google Tag Manager in API Docs.
type: feat
irVersion: 53
version: 0.46.22

- changelogEntry:
- summary: |
The CLI now supports the `prefer-undiscriminated-unions-with-literals` setting in OpenAPI settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ export async function parseDocsConfiguration({
}
: undefined,
segment: rawDocsConfiguration.analytics?.segment,
gtm: undefined,
ga4: undefined,
gtm: rawDocsConfiguration.analytics?.gtm,
ga4: rawDocsConfiguration.analytics?.ga4,
amplitude: undefined,
mixpanel: undefined,
hotjar: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export interface AnalyticsConfig {
fullstory?: FernDocsConfig.FullStoryAnalyticsConfig;
intercom?: FernDocsConfig.IntercomConfig;
posthog?: FernDocsConfig.PostHogConfig;
gtm?: FernDocsConfig.GtmConfig;
ga4?: FernDocsConfig.GoogleAnalytics4Config;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export interface GoogleAnalytics4Config {
measurementId: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export interface GtmConfig {
containerId: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export * from "./SegmentConfig";
export * from "./FullStoryAnalyticsConfig";
export * from "./IntercomConfig";
export * from "./PostHogConfig";
export * from "./GtmConfig";
export * from "./GoogleAnalytics4Config";
export * from "./DocsConfiguration";
export * from "./TabId";
export * from "./TabConfig";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { SegmentConfig } from "./SegmentConfig";
import { FullStoryAnalyticsConfig } from "./FullStoryAnalyticsConfig";
import { IntercomConfig } from "./IntercomConfig";
import { PostHogConfig } from "./PostHogConfig";
import { GtmConfig } from "./GtmConfig";
import { GoogleAnalytics4Config } from "./GoogleAnalytics4Config";

export const AnalyticsConfig: core.serialization.ObjectSchema<
serializers.AnalyticsConfig.Raw,
Expand All @@ -18,6 +20,8 @@ export const AnalyticsConfig: core.serialization.ObjectSchema<
fullstory: FullStoryAnalyticsConfig.optional(),
intercom: IntercomConfig.optional(),
posthog: PostHogConfig.optional(),
gtm: GtmConfig.optional(),
ga4: GoogleAnalytics4Config.optional(),
});

export declare namespace AnalyticsConfig {
Expand All @@ -26,5 +30,7 @@ export declare namespace AnalyticsConfig {
fullstory?: FullStoryAnalyticsConfig.Raw | null;
intercom?: IntercomConfig.Raw | null;
posthog?: PostHogConfig.Raw | null;
gtm?: GtmConfig.Raw | null;
ga4?: GoogleAnalytics4Config.Raw | null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as serializers from "../../../index";
import * as FernDocsConfig from "../../../../api/index";
import * as core from "../../../../core";

export const GoogleAnalytics4Config: core.serialization.ObjectSchema<
serializers.GoogleAnalytics4Config.Raw,
FernDocsConfig.GoogleAnalytics4Config
> = core.serialization.object({
measurementId: core.serialization.property("measurement-id", core.serialization.string()),
});

export declare namespace GoogleAnalytics4Config {
export interface Raw {
"measurement-id": string;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as serializers from "../../../index";
import * as FernDocsConfig from "../../../../api/index";
import * as core from "../../../../core";

export const GtmConfig: core.serialization.ObjectSchema<serializers.GtmConfig.Raw, FernDocsConfig.GtmConfig> =
core.serialization.object({
containerId: core.serialization.property("container-id", core.serialization.string()),
});

export declare namespace GtmConfig {
export interface Raw {
"container-id": string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export * from "./SegmentConfig";
export * from "./FullStoryAnalyticsConfig";
export * from "./IntercomConfig";
export * from "./PostHogConfig";
export * from "./GtmConfig";
export * from "./GoogleAnalytics4Config";
export * from "./DocsConfiguration";
export * from "./TabId";
export * from "./TabConfig";
Expand Down
12 changes: 10 additions & 2 deletions packages/cli/docs-resolver/src/DocsDefinitionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,16 @@ export class DocsDefinitionResolver {
endpoint: this.parsedDocsConfig.analyticsConfig.posthog.endpoint
}
: undefined,
gtm: undefined,
ga4: undefined,
gtm: this.parsedDocsConfig.analyticsConfig?.gtm
? {
containerId: this.parsedDocsConfig.analyticsConfig.gtm.containerId
}
: undefined,
ga4: this.parsedDocsConfig.analyticsConfig?.ga4
? {
measurementId: this.parsedDocsConfig.analyticsConfig.ga4.measurementId
}
: undefined,
amplitude: undefined,
mixpanel: undefined,
hotjar: undefined,
Expand Down

0 comments on commit 7f7e1ff

Please sign in to comment.