Skip to content

Commit 169c278

Browse files
cmyuiclaude
andauthored
Remove Amplitude analytics integration (#246)
Amplitude is no longer used for product analytics. This removes: - Go SDK client initialization and event tracking (login, signup, homepage) - Browser SDK snippet from base.html - JS init/user identification from akatsuki_src.js - AmplitudeLogger adapter in app/logging/ - AMPLITUDE_API_KEY from settings, .env.example, and services - amplitude/analytics-go and mileusna/useragent dependencies from go.mod Note: web/static/js/dist-*.min.js should be rebuilt via gulp after merge. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c4a1f5c commit 169c278

12 files changed

Lines changed: 3 additions & 189 deletions

File tree

.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,3 @@ RECAPTCHA_SECRET_KEY=
5151
IP_LOOKUP_URL=http://ip-api.com
5252

5353
PAYPAL_EMAIL_ADDRESS=
54-
55-
AMPLITUDE_API_KEY=

app/handlers/misc/homepage.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package misc
22

33
import (
4-
"strconv"
5-
6-
"github.com/amplitude/analytics-go/amplitude"
74
"github.com/gin-gonic/gin"
85
"github.com/osuAkatsuki/hanayo/app/models"
9-
"github.com/osuAkatsuki/hanayo/app/sessions"
10-
"github.com/osuAkatsuki/hanayo/app/states/services"
116
tu "github.com/osuAkatsuki/hanayo/app/usecases/templates"
127
)
138

@@ -17,22 +12,5 @@ func HomepagePageHandler(c *gin.Context) {
1712

1813
defer tu.Resp(c, 200, "homepage.html", data)
1914

20-
// Fire a homepage load event
21-
ctx := sessions.GetContext(c)
22-
if ctx.User.ID != 0 {
23-
services.Amplitude.Track(amplitude.Event{
24-
EventType: "homepage_load",
25-
EventOptions: amplitude.EventOptions{
26-
IP: c.ClientIP(),
27-
Country: c.Request.Header.Get("CF-IPCountry"),
28-
City: c.Request.Header.Get("CF-IPCity"),
29-
Region: c.Request.Header.Get("CF-Region"),
30-
Language: c.Request.Header.Get("Accept-Language"),
31-
UserID: strconv.Itoa(ctx.User.ID),
32-
},
33-
EventProperties: map[string]interface{}{"source": "hanayo"},
34-
})
35-
}
36-
3715
data.DisableHH = true
3816
}

app/handlers/sessions/login/login.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import (
55
"html/template"
66
"strconv"
77
"strings"
8-
"time"
98

109
"golang.org/x/exp/slog"
1110

12-
"github.com/amplitude/analytics-go/amplitude"
1311
"github.com/gin-gonic/gin"
14-
"github.com/mileusna/useragent"
1512
"github.com/osuAkatsuki/akatsuki-api/common"
1613
eh "github.com/osuAkatsuki/hanayo/app/handlers/errors"
1714
msg "github.com/osuAkatsuki/hanayo/app/models/messages"
@@ -123,53 +120,6 @@ func LoginSubmitHandler(c *gin.Context) {
123120
return
124121
}
125122

126-
latitude, err := strconv.ParseFloat(c.Request.Header.Get("CF-IPLatitude"), 64)
127-
if err != nil {
128-
slog.Error("Error parsing latitude", "error", err.Error())
129-
latitude = 0.0
130-
}
131-
132-
longitude, err := strconv.ParseFloat(c.Request.Header.Get("CF-IPLongitude"), 64)
133-
if err != nil {
134-
slog.Error("Error parsing longitude", "error", err.Error())
135-
longitude = 0.0
136-
}
137-
138-
userAgent := useragent.Parse(c.Request.UserAgent())
139-
140-
services.Amplitude.Track(amplitude.Event{
141-
EventType: "web_login",
142-
EventOptions: amplitude.EventOptions{
143-
UserID: strconv.Itoa(data.ID),
144-
IP: c.ClientIP(),
145-
Country: c.Request.Header.Get("CF-IPCountry"),
146-
City: c.Request.Header.Get("CF-IPCity"),
147-
LocationLat: latitude,
148-
LocationLng: longitude,
149-
Region: c.Request.Header.Get("CF-Region"),
150-
Language: c.Request.Header.Get("Accept-Language"),
151-
OSName: userAgent.OS,
152-
OSVersion: userAgent.OSVersion,
153-
DeviceModel: userAgent.Device,
154-
},
155-
EventProperties: map[string]interface{}{"source": "hanayo"},
156-
})
157-
158-
identifyObj := amplitude.Identify{}
159-
identifyObj.Set("last_login", time.Now().Unix())
160-
identifyObj.Set("last_login_country", data.Country)
161-
identifyObj.Set("last_login_ip", c.ClientIP())
162-
identifyObj.Set("os_name", userAgent.OS)
163-
identifyObj.Set("os_version", userAgent.OSVersion)
164-
identifyObj.Set("device_model", userAgent.Device)
165-
166-
services.Amplitude.Identify(
167-
identifyObj,
168-
amplitude.EventOptions{
169-
UserID: strconv.Itoa(data.ID),
170-
},
171-
)
172-
173123
uu.SetYCookie(data.ID, c)
174124

175125
sess.Set("userid", data.ID)

app/handlers/sessions/register/register.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import (
88

99
"golang.org/x/exp/slog"
1010

11-
"github.com/amplitude/analytics-go/amplitude"
1211
"github.com/gin-gonic/gin"
13-
"github.com/mileusna/useragent"
1412
"github.com/osuAkatsuki/akatsuki-api/common"
1513
eh "github.com/osuAkatsuki/hanayo/app/handlers/errors"
1614
"github.com/osuAkatsuki/hanayo/app/models"
@@ -192,51 +190,6 @@ func RegisterSubmitHandler(c *gin.Context) {
192190
// delete the key c
193191
//db.Exec("DELETE FROM beta_keys WHERE beta_key = ?", c.PostForm("key"))
194192

195-
latitude, err := strconv.ParseFloat(c.Request.Header.Get("CF-IPLatitude"), 64)
196-
if err != nil {
197-
slog.Error("Error parsing latitude", "error", err.Error())
198-
latitude = 0.0
199-
}
200-
201-
longitude, err := strconv.ParseFloat(c.Request.Header.Get("CF-IPLongitude"), 64)
202-
if err != nil {
203-
slog.Error("Error parsing longitude", "error", err.Error())
204-
longitude = 0.0
205-
}
206-
207-
userAgent := useragent.Parse(c.Request.UserAgent())
208-
209-
services.Amplitude.Track(amplitude.Event{
210-
EventType: "web_signup",
211-
EventOptions: amplitude.EventOptions{
212-
UserID: strconv.FormatInt(userId, 10),
213-
IP: c.ClientIP(),
214-
Country: c.Request.Header.Get("CF-IPCountry"),
215-
City: c.Request.Header.Get("CF-IPCity"),
216-
LocationLat: latitude,
217-
LocationLng: longitude,
218-
Region: c.Request.Header.Get("CF-Region"),
219-
Language: c.Request.Header.Get("Accept-Language"),
220-
OSName: userAgent.OS,
221-
OSVersion: userAgent.OSVersion,
222-
DeviceModel: userAgent.Device,
223-
},
224-
EventProperties: map[string]interface{}{"source": "hanayo"},
225-
})
226-
227-
identifyObj := amplitude.Identify{}
228-
identifyObj.SetOnce("username", username)
229-
identifyObj.SetOnce("email", email)
230-
identifyObj.SetOnce("signup_date", time.Now().Unix())
231-
identifyObj.SetOnce("signup_ip", c.ClientIP())
232-
233-
services.Amplitude.Identify(
234-
identifyObj,
235-
amplitude.EventOptions{
236-
UserID: strconv.FormatInt(userId, 10),
237-
},
238-
)
239-
240193
uu.SetYCookie(int(userId), c)
241194

242195
err = uu.LogIP(c, int(userId))

app/logging/logging.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

app/states/services/services.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package services
22

33
import (
4-
"github.com/amplitude/analytics-go/amplitude"
54
"github.com/jmoiron/sqlx"
65
csrf "github.com/osuAkatsuki/hanayo/internal/csrf"
76
"github.com/thehowl/qsql"
@@ -15,6 +14,5 @@ var (
1514
QB *qsql.DB
1615
MG mailgun.Mailgun
1716
RD *redis.Client
18-
Amplitude amplitude.Client
1917
CSRF csrf.CSRF
2018
)

app/states/settings/settings.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ type Settings struct {
8282
IP_LOOKUP_URL string
8383

8484
PAYPAL_EMAIL_ADDRESS string
85-
86-
AMPLITUDE_API_KEY string
8785
}
8886

8987
var settings = Settings{}
@@ -146,8 +144,6 @@ func LoadSettings() Settings {
146144

147145
settings.PAYPAL_EMAIL_ADDRESS = getEnv("PAYPAL_EMAIL_ADDRESS")
148146

149-
settings.AMPLITUDE_API_KEY = getEnv("AMPLITUDE_API_KEY")
150-
151147
return settings
152148
}
153149

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/osuAkatsuki/hanayo
33
go 1.21
44

55
require (
6-
github.com/amplitude/analytics-go v1.0.1
76
github.com/aws/aws-sdk-go v1.47.3
87
github.com/dustin/go-humanize v1.0.0
98
github.com/fatih/structs v1.1.0
@@ -15,7 +14,6 @@ require (
1514
github.com/johnniedoe/contrib v0.0.0-20150821124612-d553224621be
1615
github.com/joho/godotenv v1.5.1
1716
github.com/microcosm-cc/bluemonday v1.0.26
18-
github.com/mileusna/useragent v1.3.3
1917
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
2018
github.com/pariz/gountries v0.1.6
2119
github.com/rjeczalik/notify v0.9.3-0.20181126183243-629144ba06a1

go.sum

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKS
3535
github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
3636
github.com/allegro/bigcache/v2 v2.2.5 h1:mRc8r6GQjuJsmSKQNPsR5jQVXc8IJ1xsW5YXUYMLfqI=
3737
github.com/allegro/bigcache/v2 v2.2.5/go.mod h1:FppZsIO+IZk7gCuj5FiIDHGygD9xvWQcqg1uIPMb6tY=
38-
github.com/amplitude/analytics-go v1.0.1 h1:rrdC5VBctlJigSk0kw7ktwSijob/wyH4bop2SqWduCU=
39-
github.com/amplitude/analytics-go v1.0.1/go.mod h1:kAQG8OQ6aPOxZrEZ3+/NFCfxdYSyjqXZhgkjWFD3/vo=
4038
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
4139
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
4240
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
@@ -335,8 +333,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
335333
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
336334
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
337335
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
338-
github.com/mileusna/useragent v1.3.3 h1:hrIVmPevJY3ICS1Ob4yjqJToQiv2eD9iHaJBjxMihWY=
339-
github.com/mileusna/useragent v1.3.3/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc=
340336
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
341337
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
342338
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
@@ -492,17 +488,16 @@ github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3
492488
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
493489
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
494490
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
491+
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
495492
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
496-
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
497-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
498493
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
499494
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
500495
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
501496
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
502497
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
503498
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
504-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
505-
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
499+
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
500+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
506501
github.com/tevino/abool v1.2.0 h1:heAkClL8H6w+mK5md9dzsuohKeXHUpY7Vw0ZCKW+huA=
507502
github.com/tevino/abool v1.2.0/go.mod h1:qc66Pna1RiIsPa7O4Egxxs9OqkuxDX55zznh9K07Tzg=
508503
github.com/thehowl/cieca v0.0.0-20161122163418-3d95e04c9b12 h1:qRwhooiSbYeP3Bb951Ji6PvT5/94Xdbe7B6+IYLj5So=

main.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"golang.org/x/exp/slog"
1616

17-
"github.com/amplitude/analytics-go/amplitude"
1817
"github.com/fatih/structs"
1918
"github.com/gin-gonic/contrib/sessions"
2019
"github.com/gin-gonic/gin"
@@ -35,7 +34,6 @@ import (
3534
loginHandlers "github.com/osuAkatsuki/hanayo/app/handlers/sessions/login"
3635
logoutHandlers "github.com/osuAkatsuki/hanayo/app/handlers/sessions/logout"
3736
registerHandlers "github.com/osuAkatsuki/hanayo/app/handlers/sessions/register"
38-
logging "github.com/osuAkatsuki/hanayo/app/logging"
3937
middleware "github.com/osuAkatsuki/hanayo/app/middleware"
4038
msg "github.com/osuAkatsuki/hanayo/app/models/messages"
4139
sessionsmanager "github.com/osuAkatsuki/hanayo/app/sessions"
@@ -125,11 +123,6 @@ func main() {
125123
})
126124
services.RD = rd
127125

128-
amplitudeConfig := amplitude.NewConfig(settings.AMPLITUDE_API_KEY)
129-
amplitudeConfig.MinIDLength = 4 // our user ids start from 1000
130-
amplitudeConfig.Logger = (*logging.AmplitudeLogger)(logger)
131-
services.Amplitude = amplitude.NewClient(amplitudeConfig)
132-
133126
// even if it's not release, we say that it's release
134127
// so that gin doesn't spam
135128
gin.SetMode(gin.ReleaseMode)

0 commit comments

Comments
 (0)