diff --git a/claat/parser/md/parse.go b/claat/parser/md/parse.go index 346537c1c..efba695b0 100644 --- a/claat/parser/md/parse.go +++ b/claat/parser/md/parse.go @@ -45,17 +45,18 @@ import ( // Metadata constants for the YAML header const ( - MetaAuthors = "authors" - MetaSummary = "summary" - MetaID = "id" - MetaCategories = "categories" - MetaEnvironments = "environments" - MetaStatus = "status" - MetaFeedbackLink = "feedback_link" - MetaAnalyticsAccount = "analytics_account" - MetaTags = "tags" - MetaSource = "source" - MetaDuration = "duration" + MetaAuthors = "authors" + MetaSummary = "summary" + MetaID = "id" + MetaCategories = "categories" + MetaEnvironments = "environments" + MetaStatus = "status" + MetaFeedbackLink = "feedback_link" + MetaAnalyticsAccount = "analytics_account" + MetaAnalyticsGa4Account = "analytics_ga4_account" + MetaTags = "tags" + MetaSource = "source" + MetaDuration = "duration" ) const ( @@ -182,7 +183,7 @@ type docState struct { survey int // last used survey ID step *types.Step // current codelab step lastNode nodes.Node // last appended node - env []string // current enviornment + env []string // current environment cur *html.Node // current HTML node stack []*stackItem // cur and flags stack } @@ -439,6 +440,9 @@ func addMetadataToCodelab(m map[string]string, c *types.Codelab, opts parser.Opt case MetaAnalyticsAccount: // Directly assign the GA id to the codelab field. c.GA = v + case MetaAnalyticsGa4Account: + // Directly assign the GA id to the codelab field. + c.GA4 = v case MetaTags: // Standardize the tags and append to the codelab field. c.Tags = append(c.Tags, util.NormalizedSplit(v)...) diff --git a/claat/parser/md/parse_test.go b/claat/parser/md/parse_test.go index e0ef8dd93..1b39bb415 100644 --- a/claat/parser/md/parse_test.go +++ b/claat/parser/md/parse_test.go @@ -171,6 +171,7 @@ func TestParseMetadata(t *testing.T) { Tags: []string{"kiosk", "web"}, Feedback: "https://www.google.com", GA: "12345", + GA4: "54321", Extra: map[string]string{}, } @@ -181,6 +182,7 @@ summary: abcdefghij categories: not, really environments: kiosk, web analytics_account: 12345 +analytics_ga4_account: 54321 feedback_link: https://www.google.com --- @@ -204,6 +206,7 @@ func TestParseMetadataPassMetadata(t *testing.T) { Tags: []string{"kiosk", "web"}, Feedback: "https://www.google.com", GA: "12345", + GA4: "54321", Extra: map[string]string{ "extra_field_two": "bbbbb", }, @@ -216,6 +219,7 @@ summary: abcdefghij categories: not, really environments: kiosk, web analytics_account: 12345 +analytics_ga4_account: 54321 feedback_link: https://www.google.com extra_field_one: aaaaa extra_field_two: bbbbb @@ -278,6 +282,7 @@ summary: abcdefghij categories: not, really environments: kiosk, web analytics_account: 12345 +analytics_ga4_account: 54321 feedback_link: https://www.google.com extrafieldone: aaaaa extrafieldtwo: bbbbb diff --git a/claat/render/template.go b/claat/render/template.go index ad73cbc78..5a50c9607 100644 --- a/claat/render/template.go +++ b/claat/render/template.go @@ -35,14 +35,15 @@ import ( // Context is a template context during execution. type Context struct { - Env string - Prefix string - GlobalGA string - Format string - Meta *types.Meta - Steps []*types.Step - Updated string - Extra map[string]string // Extra variables passed from the command line. + Env string + Prefix string + GlobalGA string + GlobalGA4 string + Format string + Meta *types.Meta + Steps []*types.Step + Updated string + Extra map[string]string // Extra variables passed from the command line. } // Execute renders a template of the fmt format into w. @@ -104,6 +105,7 @@ var funcMap = map[string]interface{}{ res += kvLine(mdParse.MetaTags, strings.Join(meta.Tags, ",")) res += kvLine(mdParse.MetaFeedbackLink, meta.Feedback) res += kvLine(mdParse.MetaAnalyticsAccount, meta.GA) + res += kvLine(mdParse.MetaAnalyticsGa4Account, meta.GA4) res += kvLine(mdParse.MetaSource, meta.Source) res += kvLine(mdParse.MetaDuration, strconv.Itoa(meta.Duration)) diff --git a/claat/render/template.html b/claat/render/template.html index dd56bbf23..335454583 100644 --- a/claat/render/template.html +++ b/claat/render/template.html @@ -34,8 +34,9 @@ - +