ai cooking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

signal conversion (#281)

* signal conversion

* specific label

---------

Co-authored-by: paul miller <paul.miller>

authored by

Paul Miller
paul miller
and committed by
GitHub
c5ee667e 80b19d08

+43 -7
+1 -1
AGENTS.md
··· 42 42 - Keep commits scoped and reviewable; avoid mixing refactors with feature changes unless necessary. 43 43 44 44 ## Security & Configuration Notes 45 - - Required env vars: `KROGER_CLIENT_ID`, `KROGER_CLIENT_SECRET`, `AI_API_KEY`; optional `CLARITY_PROJECT_ID`, `GOOGLE_TAG_ID`, `HISTORY_PATH`. Azure logging uses `AZURE_STORAGE_ACCOUNT_NAME` and `AZURE_STORAGE_PRIMARY_ACCOUNT_KEY`. 45 + - Required env vars: `KROGER_CLIENT_ID`, `KROGER_CLIENT_SECRET`, `AI_API_KEY`; optional `CLARITY_PROJECT_ID`, `GOOGLE_TAG_ID`, `GOOGLE_CONVERSION_LABEL`, `HISTORY_PATH`. Azure logging uses `AZURE_STORAGE_ACCOUNT_NAME` and `AZURE_STORAGE_PRIMARY_ACCOUNT_KEY`. 46 46 - Never commit secrets or generated recipe outputs. If testing against real APIs, use minimal scopes and rotate keys promptly. 47 47 - Any handler that lets you see data from multiple users should go behind the /admin mux to secure it.
+1
README.md
··· 15 15 ### Optional 16 16 - `CLARITY_PROJECT_ID` - Microsoft Clarity project ID for web analytics (optional) 17 17 - `GOOGLE_TAG_ID` - Google Ads/gtag ID for web analytics (optional) 18 + - `GOOGLE_CONVERSION_LABEL` - Google Ads conversion label used on `/auth/establish?signup=true` (optional) 18 19 - `SENDGRID_API_KEY` - To allow sending weekly recipe lists via email 19 20 20 21 if you're
+2
deploy/deploy.yaml
··· 34 34 value: "td2gxd3sq9" 35 35 - name: GOOGLE_TAG_ID 36 36 value: "AW-17902827663" 37 + - name: GOOGLE_CONVERSION_LABEL 38 + value: "xDzACMu074AcEI_x3dhC" 37 39 - name: ADMIN_EMAILS 38 40 value: "paul.miller@gmail.com" 39 41 volumeMounts:
+10 -2
internal/auth/clerk.go
··· 6 6 "context" 7 7 "errors" 8 8 "fmt" 9 + "html/template" 9 10 "log/slog" 10 11 "net/http" 12 + "strings" 11 13 "time" 12 14 13 15 "github.com/clerk/clerk-sdk-go/v2" ··· 176 178 } 177 179 w.Header().Set("Content-Type", "text/html; charset=utf-8") 178 180 data := struct { 179 - PublishableKey string 181 + PublishableKey string 182 + GoogleTagScript template.HTML 183 + GoogleConversionTag string 184 + Signup bool 180 185 }{ 181 - PublishableKey: c.cfg.Clerk.PublishableKey, 186 + PublishableKey: c.cfg.Clerk.PublishableKey, 187 + GoogleTagScript: templates.GoogleTagScript(), 188 + GoogleConversionTag: templates.GoogleConversionTag(), 189 + Signup: strings.EqualFold(strings.TrimSpace(r.URL.Query().Get("signup")), "true"), 182 190 } 183 191 if err := templates.AuthEstablish.Execute(w, data); err != nil { 184 192 slog.ErrorContext(r.Context(), "auth establish template execute error", "error", err)
+4 -3
internal/config/config.go
··· 58 58 return c.ConsumerID != "" && c.PrivateKey != "" 59 59 } 60 60 61 - var locahostredirect = "?redirect_url=http://localhost:8080/auth/establish" 61 + var localhostSigninRedirect = "?redirect_url=http://localhost:8080/auth/establish" 62 + var localhostSignupRedirect = "?redirect_url=http://localhost:8080/auth/establish?signup=true" 62 63 63 64 // move to auth pacakage? 64 65 func (c *ClerkConfig) Signin() string { 65 66 url := fmt.Sprintf("https://%s/sign-in", c.Domain) 66 67 if !c.Prod { 67 - url += locahostredirect 68 + url += localhostSigninRedirect 68 69 } 69 70 return url 70 71 } ··· 72 73 func (c *ClerkConfig) Signup() string { 73 74 url := fmt.Sprintf("https://%s/sign-up", c.Domain) 74 75 if !c.Prod { 75 - url += locahostredirect 76 + url += localhostSignupRedirect 76 77 } 77 78 return url 78 79 }
+16 -1
internal/templates/auth_establish.html
··· 4 4 <meta charset="utf-8" /> 5 5 <meta name="viewport" content="width=device-width, initial-scale=1" /> 6 6 <title>Signing In</title> 7 + {{.GoogleTagScript}} 7 8 </head> 8 9 <body> 9 10 <script ··· 16 17 const url = new URL(location.href); 17 18 url.searchParams.delete("__clerk_db_jwt"); 18 19 history.replaceState({}, "", url.toString()); 19 - location.replace("/"); 20 + 21 + const redirectHome = () => location.replace("/"); 22 + 23 + if ({{.Signup}} && 24 + "{{.GoogleConversionTag}}" !== "" && 25 + typeof gtag === "function") { 26 + gtag("event", "conversion", { 27 + send_to: "{{.GoogleConversionTag}}", 28 + event_callback: redirectHome, 29 + }); 30 + setTimeout(redirectHome, 1500); 31 + return; 32 + } 33 + 34 + redirectHome(); 20 35 }); 21 36 </script> 22 37 </body>
+9
internal/templates/templates.go
··· 43 43 //todo pull from config. 44 44 Clarityproject = os.Getenv("CLARITY_PROJECT_ID") 45 45 GoogleTagID = os.Getenv("GOOGLE_TAG_ID") 46 + GoogleConversionLabel = os.Getenv("GOOGLE_CONVERSION_LABEL") 46 47 return nil 47 48 } 48 49 ··· 56 57 57 58 var Clarityproject string 58 59 var GoogleTagID string 60 + var GoogleConversionLabel string 59 61 60 62 // ClarityScript generates the Microsoft Clarity tracking script HTML 61 63 func ClarityScript() template.HTML { ··· 91 93 92 94 return template.HTML(script) 93 95 } 96 + 97 + func GoogleConversionTag() string { 98 + if GoogleTagID == "" || GoogleConversionLabel == "" { 99 + return "" 100 + } 101 + return GoogleTagID + "/" + GoogleConversionLabel 102 + }