Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.dobby.model.experiment.ExperimentPost
import com.dobby.usecase.UseCase
import com.dobby.util.EmailUtils
import com.dobby.util.RetryUtils
import com.dobby.util.UtmLinkUtils
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -70,13 +71,15 @@ class SendMatchingEmailUseCase(
return groupedPosts.flatMap { (place, posts) ->
val sortedPosts = posts.sortedBy { it.createdAt }
sortedPosts.mapIndexed { index, post ->
val postUrl = urlGeneratorGateway.getExperimentPostUrl(post.id)
val baseUrl = urlGeneratorGateway.getExperimentPostUrl(post.id)
val postUrlWithUtm = UtmLinkUtils.add(baseUrl)

mapOf(
"title" to post.title,
"place" to if (index == 0) place else "",
"uploadDate" to LocalDate.now().toString(),
"reward" to post.reward,
"postUrl" to postUrl
"postUrl" to postUrlWithUtm
)
}
}
Expand Down
11 changes: 11 additions & 0 deletions application/src/main/kotlin/com/dobby/util/UtmLinkUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dobby.util

object UtmLinkUtils {
private const val EMAIL_UTM = "utm_source=email&utm_medium=daily"

fun add(url: String, utm: String = EMAIL_UTM): String {
if (url.contains("utm_source=") || url.contains("utm_medium=")) return url
val sep = if (url.contains("?")) "&" else "?"
return url + sep + utm
}
}
33 changes: 33 additions & 0 deletions application/src/test/kotlin/com/dobby/util/UtmLinkUtilsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.dobby.util

import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.shouldBe

class UtmLinkUtilsTest : BehaviorSpec({

given("메일 트래킹 정책(utm_source=email&utm_medium=daily)") {
`when`("원본 쿼리스트링이 없는 URL이면") {
val url = "https://gradmeet.co.kr/post/123"
then("UTM이 ?로 시작하여 붙는다") {
UtmLinkUtils.add(url) shouldBe
"https://gradmeet.co.kr/post/123?utm_source=email&utm_medium=daily"
}
}

`when`("이미 쿼리스트링이 있는 URL이면") {
val url = "https://gradmeet.co.kr/post/123?param=test"
then("UTM이 &로 붙는다") {
UtmLinkUtils.add(url) shouldBe
"https://gradmeet.co.kr/post/123?param=test&utm_source=email&utm_medium=daily"
}
}

`when`("이미 동일한 UTM이 붙어 있는 URL이면") {
val url = "https://gradmeet.co.kr/321?utm_source=email&utm_medium=daily"
then("중복 추가하지 않는다") {
UtmLinkUtils.add(url) shouldBe
"https://gradmeet.co.kr/321?utm_source=email&utm_medium=daily"
}
}
}
})
Loading