tracks.go 29 KB

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