tracks.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. package analytics
  2. import (
  3. "github.com/porter-dev/porter/api/types"
  4. segment "gopkg.in/segmentio/analytics-go.v3"
  5. )
  6. type segmentTrack interface {
  7. getUserId() string
  8. getEvent() SegmentEvent
  9. getProperties() segment.Properties
  10. }
  11. type defaultTrackOpts struct {
  12. AdditionalProps map[string]interface{}
  13. }
  14. type defaultSegmentTrack struct {
  15. event SegmentEvent
  16. properties segmentProperties
  17. }
  18. func getDefaultSegmentTrack(additionalProps map[string]interface{}, event SegmentEvent) *defaultSegmentTrack {
  19. props := newSegmentProperties()
  20. props.addAdditionalProperties(additionalProps)
  21. return &defaultSegmentTrack{
  22. event: event,
  23. properties: props,
  24. }
  25. }
  26. func (t *defaultSegmentTrack) getEvent() SegmentEvent {
  27. return t.event
  28. }
  29. func (t *defaultSegmentTrack) getProperties() segment.Properties {
  30. props := segment.NewProperties()
  31. for key, val := range t.properties {
  32. props = props.Set(key, val)
  33. }
  34. return props
  35. }
  36. type segmentProperties map[string]interface{}
  37. func newSegmentProperties() segmentProperties {
  38. props := make(map[string]interface{})
  39. return props
  40. }
  41. func (p segmentProperties) addProjectProperties(opts *ProjectScopedTrackOpts) {
  42. p["proj_id"] = opts.ProjectID
  43. }
  44. func (p segmentProperties) addClusterProperties(opts *ClusterScopedTrackOpts) {
  45. p["cluster_id"] = opts.ClusterID
  46. }
  47. func (p segmentProperties) addRegistryProperties(opts *RegistryScopedTrackOpts) {
  48. p["registry_id"] = opts.RegistryID
  49. }
  50. func (p segmentProperties) addApplicationProperties(opts *ApplicationScopedTrackOpts) {
  51. p["app_name"] = opts.Name
  52. p["app_namespace"] = opts.Namespace
  53. p["chart_name"] = opts.ChartName
  54. }
  55. func (p segmentProperties) addAdditionalProperties(props map[string]interface{}) {
  56. for key, val := range props {
  57. p[key] = val
  58. }
  59. }
  60. // UserCreateTrackOpts are the options for creating a track when a user is created
  61. type UserCreateTrackOpts struct {
  62. *UserScopedTrackOpts
  63. Email string
  64. FirstName string
  65. LastName string
  66. CompanyName string
  67. ReferralMethod string
  68. }
  69. // UserCreateTrack returns a track for when a user is created
  70. func UserCreateTrack(opts *UserCreateTrackOpts) segmentTrack {
  71. additionalProps := make(map[string]interface{})
  72. additionalProps["email"] = opts.Email
  73. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  74. additionalProps["company"] = opts.CompanyName
  75. additionalProps["referral_method"] = opts.ReferralMethod
  76. return getSegmentUserTrack(
  77. opts.UserScopedTrackOpts,
  78. getDefaultSegmentTrack(additionalProps, UserCreate),
  79. )
  80. }
  81. // UserCreateTrackOpts are the options for creating a track when a user's email is verified
  82. type UserVerifyEmailTrackOpts struct {
  83. *UserScopedTrackOpts
  84. Email string
  85. }
  86. // UserVerifyEmailTrack returns a track for when a user's email is verified
  87. func UserVerifyEmailTrack(opts *UserVerifyEmailTrackOpts) segmentTrack {
  88. additionalProps := make(map[string]interface{})
  89. additionalProps["email"] = opts.Email
  90. return getSegmentUserTrack(
  91. opts.UserScopedTrackOpts,
  92. getDefaultSegmentTrack(additionalProps, UserVerifyEmail),
  93. )
  94. }
  95. // ProjectCreateDeleteTrackOpts are the options for creating a track when a project is created or deleted
  96. type ProjectCreateDeleteTrackOpts struct {
  97. *ProjectScopedTrackOpts
  98. Email string
  99. FirstName string
  100. LastName string
  101. CompanyName string
  102. }
  103. // ProjectCreateTrack returns a track for when a project is created
  104. func ProjectCreateTrack(opts *ProjectCreateDeleteTrackOpts) segmentTrack {
  105. additionalProps := make(map[string]interface{})
  106. additionalProps["email"] = opts.Email
  107. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  108. additionalProps["company"] = opts.CompanyName
  109. return getSegmentProjectTrack(
  110. opts.ProjectScopedTrackOpts,
  111. getDefaultSegmentTrack(additionalProps, ProjectCreate),
  112. )
  113. }
  114. // ProjectDeleteTrack returns a track for when a project is deleted
  115. func ProjectDeleteTrack(opts *ProjectCreateDeleteTrackOpts) segmentTrack {
  116. additionalProps := make(map[string]interface{})
  117. additionalProps["email"] = opts.Email
  118. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  119. additionalProps["company"] = opts.CompanyName
  120. return getSegmentProjectTrack(
  121. opts.ProjectScopedTrackOpts,
  122. getDefaultSegmentTrack(additionalProps, ProjectDelete),
  123. )
  124. }
  125. // ClusterDeleteTrackOpts are the options for creating a track when a cluster is deleted
  126. type ClusterDeleteTrackOpts struct {
  127. *ProjectScopedTrackOpts
  128. Email string
  129. FirstName string
  130. LastName string
  131. CompanyName string
  132. }
  133. // ClusterDeleteTrack returns a track for when a cluster is deleted
  134. func ClusterDeleteTrack(opts *ClusterDeleteTrackOpts) segmentTrack {
  135. additionalProps := make(map[string]interface{})
  136. additionalProps["email"] = opts.Email
  137. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  138. additionalProps["company"] = opts.CompanyName
  139. return getSegmentProjectTrack(
  140. opts.ProjectScopedTrackOpts,
  141. getDefaultSegmentTrack(additionalProps, ClusterDelete),
  142. )
  143. }
  144. // CostConsentOpenedTrackOpts are the options for creating a track when a user opens the cost consent
  145. type CostConsentOpenedTrackOpts struct {
  146. *UserScopedTrackOpts
  147. Provider string
  148. Email string
  149. FirstName string
  150. LastName string
  151. CompanyName string
  152. }
  153. // CostConsentCompletedTrack returns a track for when a user completes the cost consent
  154. func CostConsentOpenedTrack(opts *CostConsentOpenedTrackOpts) segmentTrack {
  155. additionalProps := make(map[string]interface{})
  156. additionalProps["provider"] = opts.Provider
  157. additionalProps["email"] = opts.Email
  158. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  159. additionalProps["company"] = opts.CompanyName
  160. return getSegmentUserTrack(
  161. opts.UserScopedTrackOpts,
  162. getDefaultSegmentTrack(additionalProps, CostConsentOpened),
  163. )
  164. }
  165. // CostConsentCompletedTrackOpts are the options for creating a track when a user completes the cost consent
  166. type CostConsentCompletedTrackOpts struct {
  167. *UserScopedTrackOpts
  168. Provider string
  169. Email string
  170. FirstName string
  171. LastName string
  172. CompanyName string
  173. }
  174. // CostConsentCompletedTrack returns a track for when a user completes the cost consent
  175. func CostConsentCompletedTrack(opts *CostConsentCompletedTrackOpts) segmentTrack {
  176. additionalProps := make(map[string]interface{})
  177. additionalProps["provider"] = opts.Provider
  178. additionalProps["email"] = opts.Email
  179. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  180. additionalProps["company"] = opts.CompanyName
  181. return getSegmentUserTrack(
  182. opts.UserScopedTrackOpts,
  183. getDefaultSegmentTrack(additionalProps, CostConsentComplete),
  184. )
  185. }
  186. // AWSInputTrackOpts are the options for creating a track when a user inputs a complete AWS account ID
  187. type AWSInputTrackOpts struct {
  188. *ProjectScopedTrackOpts
  189. Email string
  190. FirstName string
  191. LastName string
  192. CompanyName string
  193. AccountId string
  194. }
  195. // AWSInputTrack returns a track for when a user inputs a complete AWS account ID
  196. func AWSInputTrack(opts *AWSInputTrackOpts) segmentTrack {
  197. additionalProps := make(map[string]interface{})
  198. additionalProps["email"] = opts.Email
  199. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  200. additionalProps["company"] = opts.CompanyName
  201. additionalProps["account_id"] = opts.AccountId
  202. return getSegmentProjectTrack(
  203. opts.ProjectScopedTrackOpts,
  204. getDefaultSegmentTrack(additionalProps, AWSInputted),
  205. )
  206. }
  207. type AWSRedirectOpts struct {
  208. *ProjectScopedTrackOpts
  209. Email string
  210. FirstName string
  211. LastName string
  212. CompanyName string
  213. AccountId string
  214. CloudformationURL string
  215. LoginURL string
  216. ExternalId string
  217. }
  218. // AWSCloudformationRedirectSuccess returns a track for when a user clicks 'grant permissions' and gets redirected to cloudformation
  219. func AWSCloudformationRedirectSuccess(opts *AWSRedirectOpts) segmentTrack {
  220. additionalProps := make(map[string]interface{})
  221. additionalProps["email"] = opts.Email
  222. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  223. additionalProps["company"] = opts.CompanyName
  224. additionalProps["account_id"] = opts.AccountId
  225. additionalProps["cloudformation_url"] = opts.CloudformationURL
  226. additionalProps["external_id"] = opts.ExternalId
  227. return getSegmentProjectTrack(
  228. opts.ProjectScopedTrackOpts,
  229. getDefaultSegmentTrack(additionalProps, AWSCloudformationRedirect),
  230. )
  231. }
  232. // AWSLoginRedirectSuccess returns a track for when a user is prompted to login to AWS
  233. func AWSLoginRedirectSuccess(opts *AWSRedirectOpts) segmentTrack {
  234. additionalProps := make(map[string]interface{})
  235. additionalProps["email"] = opts.Email
  236. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  237. additionalProps["company"] = opts.CompanyName
  238. additionalProps["account_id"] = opts.AccountId
  239. additionalProps["login_url"] = opts.LoginURL
  240. return getSegmentProjectTrack(
  241. opts.ProjectScopedTrackOpts,
  242. getDefaultSegmentTrack(additionalProps, AWSLoginRedirect),
  243. )
  244. }
  245. type AWSCreateIntegrationOpts struct {
  246. *ProjectScopedTrackOpts
  247. Email string
  248. FirstName string
  249. LastName string
  250. CompanyName string
  251. AccountId string
  252. ExternalId string
  253. ErrorMessage string
  254. }
  255. // AWSCreateIntegrationSucceeded returns a track for when a user succeeds in creating an aws integration
  256. func AWSCreateIntegrationSucceeded(opts *AWSCreateIntegrationOpts) segmentTrack {
  257. additionalProps := make(map[string]interface{})
  258. additionalProps["email"] = opts.Email
  259. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  260. additionalProps["company"] = opts.CompanyName
  261. additionalProps["account_id"] = opts.AccountId
  262. return getSegmentProjectTrack(
  263. opts.ProjectScopedTrackOpts,
  264. getDefaultSegmentTrack(additionalProps, AWSCreateIntegrationSuccess),
  265. )
  266. }
  267. // AWSCreateIntegrationSucceeded returns a track for when a user succeeds in creating an aws integration
  268. func AWSCreateIntegrationFailed(opts *AWSCreateIntegrationOpts) segmentTrack {
  269. additionalProps := make(map[string]interface{})
  270. additionalProps["email"] = opts.Email
  271. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  272. additionalProps["company"] = opts.CompanyName
  273. additionalProps["account_id"] = opts.AccountId
  274. additionalProps["error_message"] = opts.ErrorMessage
  275. additionalProps["external_id"] = opts.ExternalId
  276. return getSegmentProjectTrack(
  277. opts.ProjectScopedTrackOpts,
  278. getDefaultSegmentTrack(additionalProps, AWSCreateIntegrationFailure),
  279. )
  280. }
  281. // CredentialStepTrackOpts are the options for creating a track when a user completes the credential step
  282. type CredentialStepTrackOpts struct {
  283. *UserScopedTrackOpts
  284. }
  285. // CredentialStepTrack returns a track for when a user completes the credential step
  286. func CredentialStepTrack(opts *CredentialStepTrackOpts) segmentTrack {
  287. additionalProps := make(map[string]interface{})
  288. return getSegmentUserTrack(
  289. opts.UserScopedTrackOpts,
  290. getDefaultSegmentTrack(additionalProps, CredentialStepComplete),
  291. )
  292. }
  293. // PreProvisionCheckTrackOpts are the options for creating a track when a user checks if they can provision
  294. type PreProvisionCheckTrackOpts struct {
  295. *ProjectScopedTrackOpts
  296. Email string
  297. FirstName string
  298. LastName string
  299. CompanyName string
  300. }
  301. // PreProvisionCheckTrack returns a track for when a user attempts provisioning
  302. func PreProvisionCheckTrack(opts *PreProvisionCheckTrackOpts) segmentTrack {
  303. additionalProps := make(map[string]interface{})
  304. additionalProps["email"] = opts.Email
  305. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  306. additionalProps["company"] = opts.CompanyName
  307. return getSegmentProjectTrack(
  308. opts.ProjectScopedTrackOpts,
  309. getDefaultSegmentTrack(additionalProps, PreProvisionCheck),
  310. )
  311. }
  312. // ProvisioningAttemptedTrackOpts are the options for creating a track when a user attempts provisioning
  313. type ProvisioningAttemptTrackOpts struct {
  314. *ProjectScopedTrackOpts
  315. Email string
  316. FirstName string
  317. LastName string
  318. CompanyName string
  319. ErrorMessage string
  320. Region string
  321. Provider string
  322. }
  323. // ProvisioningAttemptTrack returns a track for when a user attempts provisioning
  324. func ProvisioningAttemptTrack(opts *ProvisioningAttemptTrackOpts) segmentTrack {
  325. additionalProps := make(map[string]interface{})
  326. additionalProps["email"] = opts.Email
  327. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  328. additionalProps["company"] = opts.CompanyName
  329. additionalProps["region"] = opts.Region
  330. additionalProps["provider"] = opts.Provider
  331. return getSegmentProjectTrack(
  332. opts.ProjectScopedTrackOpts,
  333. getDefaultSegmentTrack(additionalProps, ProvisioningAttempted),
  334. )
  335. }
  336. // PreProvisionCheckTrack returns a track for when a user attempts provisioning
  337. func ProvisionFailureTrack(opts *ProvisioningAttemptTrackOpts) segmentTrack {
  338. additionalProps := make(map[string]interface{})
  339. additionalProps["email"] = opts.Email
  340. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  341. additionalProps["company"] = opts.CompanyName
  342. additionalProps["error_message"] = opts.ErrorMessage
  343. additionalProps["region"] = opts.Region
  344. return getSegmentProjectTrack(
  345. opts.ProjectScopedTrackOpts,
  346. getDefaultSegmentTrack(additionalProps, ProvisioningFailure),
  347. )
  348. }
  349. // ClusterProvisioningStartTrackOpts are the options for creating a track when a cluster
  350. // has started provisioning
  351. type ClusterProvisioningStartTrackOpts struct {
  352. // note that this is a project-scoped track, since the cluster has not been created yet
  353. *ProjectScopedTrackOpts
  354. ClusterType types.InfraKind
  355. InfraID uint
  356. }
  357. // ClusterProvisioningStartTrack returns a track for when a cluster
  358. // has started provisioning
  359. func ClusterProvisioningStartTrack(opts *ClusterProvisioningStartTrackOpts) segmentTrack {
  360. additionalProps := make(map[string]interface{})
  361. additionalProps["cluster_type"] = opts.ClusterType
  362. additionalProps["infra_id"] = opts.InfraID
  363. return getSegmentProjectTrack(
  364. opts.ProjectScopedTrackOpts,
  365. getDefaultSegmentTrack(additionalProps, ClusterProvisioningStart),
  366. )
  367. }
  368. // ClusterProvisioningErrorTrackOpts are the options for creating a track when a cluster
  369. // has experienced a provisioning error
  370. type ClusterProvisioningErrorTrackOpts struct {
  371. // note that this is a project-scoped track, since the cluster has not been created yet
  372. *ProjectScopedTrackOpts
  373. ClusterType types.InfraKind
  374. InfraID uint
  375. }
  376. // ClusterProvisioningErrorTrack returns a track for when a cluster
  377. // has experienced a provisioning error
  378. func ClusterProvisioningErrorTrack(opts *ClusterProvisioningErrorTrackOpts) segmentTrack {
  379. additionalProps := make(map[string]interface{})
  380. additionalProps["cluster_type"] = opts.ClusterType
  381. additionalProps["infra_id"] = opts.InfraID
  382. return getSegmentProjectTrack(
  383. opts.ProjectScopedTrackOpts,
  384. getDefaultSegmentTrack(additionalProps, ClusterProvisioningError),
  385. )
  386. }
  387. // ClusterProvisioningSuccessTrackOpts are the options for creating a track when a cluster
  388. // has successfully provisioned
  389. type ClusterProvisioningSuccessTrackOpts struct {
  390. *ClusterScopedTrackOpts
  391. ClusterType types.InfraKind
  392. InfraID uint
  393. }
  394. // ClusterProvisioningSuccessTrack returns a new track for when a cluster
  395. // has successfully provisioned
  396. func ClusterProvisioningSuccessTrack(opts *ClusterProvisioningSuccessTrackOpts) segmentTrack {
  397. additionalProps := make(map[string]interface{})
  398. additionalProps["cluster_type"] = opts.ClusterType
  399. additionalProps["infra_id"] = opts.InfraID
  400. return getSegmentClusterTrack(
  401. opts.ClusterScopedTrackOpts,
  402. getDefaultSegmentTrack(additionalProps, ClusterProvisioningSuccess),
  403. )
  404. }
  405. // ClusterConnectionStartTrackOpts are the options for creating a track when a cluster
  406. // connection has started
  407. type ClusterConnectionStartTrackOpts struct {
  408. // note that this is a project-scoped track, since the cluster has not been created yet
  409. *ProjectScopedTrackOpts
  410. ClusterCandidateID uint
  411. }
  412. // ClusterConnectionStartTrack returns a new track for when a cluster
  413. // connection has started
  414. func ClusterConnectionStartTrack(opts *ClusterConnectionStartTrackOpts) segmentTrack {
  415. additionalProps := make(map[string]interface{})
  416. additionalProps["cc_id"] = opts.ClusterCandidateID
  417. return getSegmentProjectTrack(
  418. opts.ProjectScopedTrackOpts,
  419. getDefaultSegmentTrack(additionalProps, ClusterConnectionStart),
  420. )
  421. }
  422. // ClusterConnectionSuccessTrackOpts are the options for creating a track when a cluster
  423. // connection has finished
  424. type ClusterConnectionSuccessTrackOpts struct {
  425. *ClusterScopedTrackOpts
  426. ClusterCandidateID uint
  427. }
  428. // ClusterConnectionSuccessTrack returns a new track for when a cluster
  429. // connection has finished
  430. func ClusterConnectionSuccessTrack(opts *ClusterConnectionSuccessTrackOpts) segmentTrack {
  431. additionalProps := make(map[string]interface{})
  432. additionalProps["cc_id"] = opts.ClusterCandidateID
  433. return getSegmentClusterTrack(
  434. opts.ClusterScopedTrackOpts,
  435. getDefaultSegmentTrack(additionalProps, ClusterConnectionSuccess),
  436. )
  437. }
  438. // RegistryConnectionStartTrackOpts are the options for creating a track when a registry
  439. // connection has started
  440. type RegistryConnectionStartTrackOpts struct {
  441. // note that this is a project-scoped track, since the cluster has not been created yet
  442. *ProjectScopedTrackOpts
  443. // a random id assigned to this connection request
  444. FlowID string
  445. }
  446. // RegistryConnectionStartTrack returns a new track for when a registry
  447. // connection has started
  448. func RegistryConnectionStartTrack(opts *RegistryConnectionStartTrackOpts) segmentTrack {
  449. additionalProps := make(map[string]interface{})
  450. additionalProps["flow_id"] = opts.FlowID
  451. return getSegmentProjectTrack(
  452. opts.ProjectScopedTrackOpts,
  453. getDefaultSegmentTrack(additionalProps, RegistryConnectionStart),
  454. )
  455. }
  456. // RegistryConnectionSuccessTrackOpts are the options for creating a track when a registry
  457. // connection has completed
  458. type RegistryConnectionSuccessTrackOpts struct {
  459. *RegistryScopedTrackOpts
  460. // a random id assigned to this connection request
  461. FlowID string
  462. }
  463. // RegistryConnectionSuccessTrack returns a new track for when a registry
  464. // connection has completed
  465. func RegistryConnectionSuccessTrack(opts *RegistryConnectionSuccessTrackOpts) segmentTrack {
  466. additionalProps := make(map[string]interface{})
  467. additionalProps["flow_id"] = opts.FlowID
  468. return getSegmentRegistryTrack(
  469. opts.RegistryScopedTrackOpts,
  470. getDefaultSegmentTrack(additionalProps, RegistryConnectionSuccess),
  471. )
  472. }
  473. // GithubConnectionStartTrackOpts are the options for creating a track when a github account
  474. // connection has started
  475. type GithubConnectionStartTrackOpts struct {
  476. // note that this is a user-scoped track, since github repos are tied to the user
  477. *UserScopedTrackOpts
  478. }
  479. // GithubConnectionStartTrack returns a new track for when a github account
  480. // connection has started
  481. func GithubConnectionStartTrack(opts *GithubConnectionStartTrackOpts) segmentTrack {
  482. additionalProps := make(map[string]interface{})
  483. return getSegmentUserTrack(
  484. opts.UserScopedTrackOpts,
  485. getDefaultSegmentTrack(additionalProps, GithubConnectionStart),
  486. )
  487. }
  488. // GithubConnectionSuccessTrackOpts are the options for creating a track when a github account
  489. // connection has completed
  490. type GithubConnectionSuccessTrackOpts struct {
  491. // note that this is a user-scoped track, since github repos are tied to the user
  492. *UserScopedTrackOpts
  493. }
  494. // GithubConnectionSuccessTrack returns a new track when a github account
  495. // connection has completed
  496. func GithubConnectionSuccessTrack(opts *GithubConnectionSuccessTrackOpts) segmentTrack {
  497. additionalProps := make(map[string]interface{})
  498. return getSegmentUserTrack(
  499. opts.UserScopedTrackOpts,
  500. getDefaultSegmentTrack(additionalProps, GithubConnectionSuccess),
  501. )
  502. }
  503. // ApplicationLaunchStartTrackOpts are the options for creating a track when an application
  504. // launch has started
  505. type ApplicationLaunchStartTrackOpts struct {
  506. *ClusterScopedTrackOpts
  507. FlowID string
  508. }
  509. // ApplicationLaunchStartTrack returns a new track for when an application
  510. // launch has started
  511. func ApplicationLaunchStartTrack(opts *ApplicationLaunchStartTrackOpts) segmentTrack {
  512. additionalProps := make(map[string]interface{})
  513. additionalProps["flow_id"] = opts.FlowID
  514. return getSegmentClusterTrack(
  515. opts.ClusterScopedTrackOpts,
  516. getDefaultSegmentTrack(additionalProps, ApplicationLaunchStart),
  517. )
  518. }
  519. // ApplicationLaunchSuccessTrackOpts are the options for creating a track when an application
  520. // launch has completed
  521. type ApplicationLaunchSuccessTrackOpts struct {
  522. *ApplicationScopedTrackOpts
  523. FlowID string
  524. }
  525. // ApplicationLaunchSuccessTrack returns a new track for when an application
  526. // launch has completed
  527. func ApplicationLaunchSuccessTrack(opts *ApplicationLaunchSuccessTrackOpts) segmentTrack {
  528. additionalProps := make(map[string]interface{})
  529. additionalProps["flow_id"] = opts.FlowID
  530. return getSegmentApplicationTrack(
  531. opts.ApplicationScopedTrackOpts,
  532. getDefaultSegmentTrack(additionalProps, ApplicationLaunchSuccess),
  533. )
  534. }
  535. // ApplicationDeploymentWebhookTrackOpts are the options for creating a track when an application
  536. // launch has completed from a webhook
  537. type ApplicationDeploymentWebhookTrackOpts struct {
  538. *ApplicationScopedTrackOpts
  539. ImageURI string
  540. }
  541. // ApplicationDeploymentWebhookTrack returns a new track for when an application
  542. // launch has completed from a webhook
  543. func ApplicationDeploymentWebhookTrack(opts *ApplicationDeploymentWebhookTrackOpts) segmentTrack {
  544. additionalProps := make(map[string]interface{})
  545. additionalProps["image_uri"] = opts.ImageURI
  546. return getSegmentApplicationTrack(
  547. opts.ApplicationScopedTrackOpts,
  548. getDefaultSegmentTrack(additionalProps, ApplicationDeploymentWebhook),
  549. )
  550. }
  551. // RegistryProvisioningStartTrackOpts are the options for creating a track when a registry
  552. // provisioning has started
  553. type RegistryProvisioningStartTrackOpts struct {
  554. // note that this is a project-scoped track, since the registry has not been created yet
  555. *ProjectScopedTrackOpts
  556. RegistryType types.InfraKind
  557. InfraID uint
  558. }
  559. // RegistryProvisioningStartTrack returns a new track for when a registry
  560. // provisioning has started
  561. func RegistryProvisioningStartTrack(opts *RegistryProvisioningStartTrackOpts) segmentTrack {
  562. additionalProps := make(map[string]interface{})
  563. additionalProps["registry_type"] = opts.RegistryType
  564. additionalProps["infra_id"] = opts.InfraID
  565. return getSegmentProjectTrack(
  566. opts.ProjectScopedTrackOpts,
  567. getDefaultSegmentTrack(additionalProps, RegistryProvisioningStart),
  568. )
  569. }
  570. // RegistryProvisioningErrorTrackOpts are the options for creating a track when a registry
  571. // provisioning has failed
  572. type RegistryProvisioningErrorTrackOpts struct {
  573. // note that this is a project-scoped track, since the registry has not been created yet
  574. *ProjectScopedTrackOpts
  575. RegistryType types.InfraKind
  576. InfraID uint
  577. }
  578. // RegistryProvisioningErrorTrack returns a new track for when a registry
  579. // provisioning has failed
  580. func RegistryProvisioningErrorTrack(opts *RegistryProvisioningErrorTrackOpts) segmentTrack {
  581. additionalProps := make(map[string]interface{})
  582. additionalProps["registry_type"] = opts.RegistryType
  583. additionalProps["infra_id"] = opts.InfraID
  584. return getSegmentProjectTrack(
  585. opts.ProjectScopedTrackOpts,
  586. getDefaultSegmentTrack(additionalProps, RegistryProvisioningError),
  587. )
  588. }
  589. // RegistryProvisioningSuccessTrackOpts are the options for creating a track when a registry
  590. // provisioning has completed
  591. type RegistryProvisioningSuccessTrackOpts struct {
  592. *RegistryScopedTrackOpts
  593. RegistryType types.InfraKind
  594. InfraID uint
  595. }
  596. // RegistryProvisioningSuccessTrack returns a new track for when a registry
  597. // provisioning has completed
  598. func RegistryProvisioningSuccessTrack(opts *RegistryProvisioningSuccessTrackOpts) segmentTrack {
  599. additionalProps := make(map[string]interface{})
  600. additionalProps["registry_type"] = opts.RegistryType
  601. additionalProps["infra_id"] = opts.InfraID
  602. return getSegmentRegistryTrack(
  603. opts.RegistryScopedTrackOpts,
  604. getDefaultSegmentTrack(additionalProps, RegistryProvisioningSuccess),
  605. )
  606. }
  607. // ClusterDestroyingStartTrackOpts are the options for creating a track when a cluster
  608. // has started destroying
  609. type ClusterDestroyingStartTrackOpts struct {
  610. *ClusterScopedTrackOpts
  611. ClusterType types.InfraKind
  612. InfraID uint
  613. }
  614. // ClusterDestroyingStartTrack returns a track for when a cluster
  615. // has started destroying
  616. func ClusterDestroyingStartTrack(opts *ClusterDestroyingStartTrackOpts) segmentTrack {
  617. additionalProps := make(map[string]interface{})
  618. additionalProps["cluster_type"] = opts.ClusterType
  619. additionalProps["infra_id"] = opts.InfraID
  620. return getSegmentClusterTrack(
  621. opts.ClusterScopedTrackOpts,
  622. getDefaultSegmentTrack(additionalProps, ClusterDestroyingStart),
  623. )
  624. }
  625. // ClusterDestroyingSuccessTrackOpts are the options for creating a track when a cluster
  626. // has successfully provisioned
  627. type ClusterDestroyingSuccessTrackOpts struct {
  628. *ClusterScopedTrackOpts
  629. ClusterType types.InfraKind
  630. InfraID uint
  631. }
  632. // ClusterDestroyingSuccessTrack returns a new track for when a cluster
  633. // has successfully provisioned
  634. func ClusterDestroyingSuccessTrack(opts *ClusterDestroyingSuccessTrackOpts) segmentTrack {
  635. additionalProps := make(map[string]interface{})
  636. additionalProps["cluster_type"] = opts.ClusterType
  637. additionalProps["infra_id"] = opts.InfraID
  638. return getSegmentClusterTrack(
  639. opts.ClusterScopedTrackOpts,
  640. getDefaultSegmentTrack(additionalProps, ClusterDestroyingSuccess),
  641. )
  642. }
  643. // StackLaunchStartOpts are the options for creating a track when a user starts creating a stack
  644. type StackLaunchStartOpts struct {
  645. *ProjectScopedTrackOpts
  646. Email string
  647. FirstName string
  648. LastName string
  649. CompanyName string
  650. }
  651. // StackLaunchStartTrack returns a track for when a user starts creating a stack
  652. func StackLaunchStartTrack(opts *StackLaunchStartOpts) segmentTrack {
  653. additionalProps := make(map[string]interface{})
  654. additionalProps["email"] = opts.Email
  655. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  656. additionalProps["company"] = opts.CompanyName
  657. return getSegmentProjectTrack(
  658. opts.ProjectScopedTrackOpts,
  659. getDefaultSegmentTrack(additionalProps, StackLaunchStart),
  660. )
  661. }
  662. // StackLaunchCompleteOpts are the options for creating a track when a user completes creating a stack
  663. type StackLaunchCompleteOpts struct {
  664. *ProjectScopedTrackOpts
  665. StackName string
  666. Email string
  667. FirstName string
  668. LastName string
  669. CompanyName string
  670. }
  671. // StackLaunchCompleteTrack returns a track for when a user completes creating a stack
  672. func StackLaunchCompleteTrack(opts *StackLaunchCompleteOpts) segmentTrack {
  673. additionalProps := make(map[string]interface{})
  674. additionalProps["stack_name"] = opts.StackName
  675. additionalProps["email"] = opts.Email
  676. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  677. additionalProps["company"] = opts.CompanyName
  678. return getSegmentProjectTrack(
  679. opts.ProjectScopedTrackOpts,
  680. getDefaultSegmentTrack(additionalProps, StackLaunchComplete),
  681. )
  682. }
  683. // StackLaunchSuccessOpts are the options for creating a track when a user succeeds in creating a stack
  684. type StackLaunchSuccessOpts struct {
  685. *ProjectScopedTrackOpts
  686. StackName string
  687. Email string
  688. FirstName string
  689. LastName string
  690. CompanyName string
  691. }
  692. // StackLaunchCompleteTrack returns a track for when a user completes creating a stack
  693. func StackLaunchSuccessTrack(opts *StackLaunchSuccessOpts) segmentTrack {
  694. additionalProps := make(map[string]interface{})
  695. additionalProps["stack_name"] = opts.StackName
  696. additionalProps["email"] = opts.Email
  697. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  698. additionalProps["company"] = opts.CompanyName
  699. return getSegmentProjectTrack(
  700. opts.ProjectScopedTrackOpts,
  701. getDefaultSegmentTrack(additionalProps, StackLaunchSuccess),
  702. )
  703. }
  704. // StackLaunchFailureOpts are the options for creating a track when a user fails in creating a stack
  705. type StackLaunchFailureOpts struct {
  706. *ProjectScopedTrackOpts
  707. StackName string
  708. Email string
  709. FirstName string
  710. LastName string
  711. CompanyName string
  712. ErrorMessage string
  713. }
  714. // StackLaunchFailureTrack returns a track for when a user fails creating a stack
  715. func StackLaunchFailureTrack(opts *StackLaunchFailureOpts) segmentTrack {
  716. additionalProps := make(map[string]interface{})
  717. additionalProps["stack_name"] = opts.StackName
  718. additionalProps["email"] = opts.Email
  719. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  720. additionalProps["company"] = opts.CompanyName
  721. additionalProps["error_message"] = opts.ErrorMessage
  722. return getSegmentProjectTrack(
  723. opts.ProjectScopedTrackOpts,
  724. getDefaultSegmentTrack(additionalProps, StackLaunchFailure),
  725. )
  726. }
  727. // StackDeletionOpts are the options for creating a track when a user deletes a stack
  728. type StackDeletionOpts struct {
  729. *ProjectScopedTrackOpts
  730. StackName string
  731. Email string
  732. FirstName string
  733. LastName string
  734. CompanyName string
  735. DeleteWorkflowFile bool
  736. }
  737. // StackDeletionTrack returns a track for when a user deletes a stack
  738. func StackDeletionTrack(opts *StackDeletionOpts) segmentTrack {
  739. additionalProps := make(map[string]interface{})
  740. additionalProps["stack_name"] = opts.StackName
  741. additionalProps["email"] = opts.Email
  742. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  743. additionalProps["company"] = opts.CompanyName
  744. additionalProps["delete_workflow_file"] = opts.DeleteWorkflowFile
  745. return getSegmentProjectTrack(
  746. opts.ProjectScopedTrackOpts,
  747. getDefaultSegmentTrack(additionalProps, StackDeletion),
  748. )
  749. }
  750. // StackBuildOpts are the options for creating a track when a stack builds
  751. type StackBuildOpts struct {
  752. *ProjectScopedTrackOpts
  753. StackName string
  754. ErrorMessage string
  755. Email string
  756. FirstName string
  757. LastName string
  758. CompanyName string
  759. }
  760. // StackBuildFailureTrack returns a track for when a stack fails to build
  761. func StackBuildFailureTrack(opts *StackBuildOpts) segmentTrack {
  762. additionalProps := make(map[string]interface{})
  763. additionalProps["stack_name"] = opts.StackName
  764. additionalProps["error_message"] = opts.ErrorMessage
  765. additionalProps["email"] = opts.Email
  766. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  767. additionalProps["company"] = opts.CompanyName
  768. return getSegmentProjectTrack(
  769. opts.ProjectScopedTrackOpts,
  770. getDefaultSegmentTrack(additionalProps, StackBuildFailure),
  771. )
  772. }
  773. // StackBuildSuccessTrack returns a track for when a stack succeeds to build
  774. func StackBuildSuccessTrack(opts *StackBuildOpts) segmentTrack {
  775. additionalProps := make(map[string]interface{})
  776. additionalProps["stack_name"] = opts.StackName
  777. additionalProps["email"] = opts.Email
  778. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  779. additionalProps["company"] = opts.CompanyName
  780. return getSegmentProjectTrack(
  781. opts.ProjectScopedTrackOpts,
  782. getDefaultSegmentTrack(additionalProps, StackBuildSuccess),
  783. )
  784. }
  785. // StackBuildProgressingTrack returns a track for when a stack starts to build
  786. func StackBuildProgressingTrack(opts *StackBuildOpts) segmentTrack {
  787. additionalProps := make(map[string]interface{})
  788. additionalProps["stack_name"] = opts.StackName
  789. additionalProps["email"] = opts.Email
  790. additionalProps["name"] = opts.FirstName + " " + opts.LastName
  791. additionalProps["company"] = opts.CompanyName
  792. return getSegmentProjectTrack(
  793. opts.ProjectScopedTrackOpts,
  794. getDefaultSegmentTrack(additionalProps, StackBuildProgressing),
  795. )
  796. }