Copied to your clipboard
val expId = ContentAnalytics.registerExperience(
assets = listOf(ContentItem("https://example.com/hero.jpg", emptyMap())),
texts = listOf(ContentItem("Buy Now", mapOf("role" to "headline"))),
ctas = listOf(ContentItem("Shop", mapOf("enabled" to true)))
)
ContentAnalytics.trackExperienceView(expId, "homepage.hero")
ContentAnalytics.trackExperienceClick(expId, "homepage.hero")
Copied to your clipboard
let expId = ContentAnalytics.registerExperience(
assets: [ContentItem(value: "https://example.com/hero.jpg", styles: [:])],
texts: [ContentItem(value: "Buy Now", styles: ["role": "headline"])],
ctas: [ContentItem(value: "Shop", styles: ["enabled": true])]
)
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "homepage.hero")
ContentAnalytics.trackExperienceClick(experienceId: expId, experienceLocation: "homepage.hero")
Copied to your clipboard
let experienceId = ContentAnalytics.registerExperience(
assets: [
ContentItem(value: "https://example.com/hero.jpg", styles: [:]),
ContentItem(value: "https://example.com/icon.png", styles: [:])
],
texts: [
ContentItem(value: "iPhone 16 Pro", styles: ["role": "headline"]),
ContentItem(value: "Forged in titanium", styles: ["role": "body"]),
ContentItem(value: "$999", styles: ["role": "price"])
],
ctas: [
ContentItem(value: "Buy Now", styles: ["enabled": true])
]
)
Copied to your clipboard
val experienceId = ContentAnalytics.registerExperience(
assets = listOf(
ContentItem("https://example.com/hero.jpg", emptyMap()),
ContentItem("https://example.com/icon.png", emptyMap())
),
texts = listOf(
ContentItem("iPhone 16 Pro", mapOf("role" to "headline")),
ContentItem("Forged in titanium", mapOf("role" to "body")),
ContentItem("$999", mapOf("role" to "price"))
),
ctas = listOf(
ContentItem("Buy Now", mapOf("enabled" to true))
)
)
Copied to your clipboard
ContentAnalytics.trackExperienceView(experienceId: experienceId, experienceLocation: "product.detail")
ContentAnalytics.trackExperienceClick(experienceId: experienceId, experienceLocation: "product.detail")
Copied to your clipboard
ContentAnalytics.trackExperienceView(experienceId, "product.detail")
ContentAnalytics.trackExperienceClick(experienceId, "product.detail")
Copied to your clipboard
let expId = ContentAnalytics.registerExperience(
assets: [ContentItem(value: "https://example.com/hero.jpg", styles: [:])],
texts: [ContentItem(value: "Title", styles: ["role": "headline"])]
)
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "home")
Copied to your clipboard
val expId = ContentAnalytics.registerExperience(
assets = listOf(ContentItem("https://example.com/hero.jpg", emptyMap())),
texts = listOf(ContentItem("Title", mapOf("role" to "headline")))
)
ContentAnalytics.trackExperienceView(expId, "home")
Copied to your clipboard
class ProductDetailViewController {
var experienceId: String?
override func viewDidLoad() {
super.viewDidLoad()
experienceId = ContentAnalytics.registerExperience(
assets: product.imageURLs.map { ContentItem(value: $0, styles: [:]) },
texts: [
ContentItem(value: product.name, styles: ["role": "headline"]),
ContentItem(value: product.price, styles: ["role": "price"])
],
ctas: [ContentItem(value: "Add to Cart", styles: ["enabled": true])]
)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if let expId = experienceId {
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "product.detail.\(product.id)")
}
}
@IBAction func buyButtonTapped(_ sender: Any) {
if let expId = experienceId {
ContentAnalytics.trackExperienceClick(experienceId: expId, experienceLocation: "product.detail.\(product.id)")
}
}
}
Copied to your clipboard
class ProductDetailActivity : AppCompatActivity() {
private var experienceId: String? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_product_detail)
experienceId = ContentAnalytics.registerExperience(
assets = product.imageURLs.map { ContentItem(it, emptyMap()) },
texts = listOf(
ContentItem(product.name, mapOf("role" to "headline")),
ContentItem(product.price, mapOf("role" to "price"))
),
ctas = listOf(ContentItem("Add to Cart", mapOf("enabled" to true)))
)
}
override fun onResume() {
super.onResume()
experienceId?.let { expId ->
ContentAnalytics.trackExperienceView(expId, "product.detail.${product.id}")
}
}
fun onBuyButtonClicked() {
experienceId?.let { expId ->
ContentAnalytics.trackExperienceClick(expId, "product.detail.${product.id}")
}
}
}
Copied to your clipboard
class FeedViewController: UIViewController {
var experienceIds: [String: String] = [:]
func displayProduct(_ product: Product) {
if experienceIds[product.id] == nil {
let expId = ContentAnalytics.registerExperience(
assets: product.imageURLs.map { ContentItem(value: $0, styles: [:]) },
texts: [ContentItem(value: product.name, styles: ["role": "headline"])]
)
experienceIds[product.id] = expId
}
}
func productCellBecameVisible(_ product: Product) {
if let expId = experienceIds[product.id] {
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "feed.item.\(product.id)")
}
}
}
Copied to your clipboard
class FeedFragment : Fragment() {
private val experienceIds = mutableMapOf<String, String>()
fun displayProduct(product: Product) {
if (!experienceIds.containsKey(product.id)) {
val expId = ContentAnalytics.registerExperience(
assets = product.imageURLs.map { ContentItem(it, emptyMap()) },
texts = listOf(ContentItem(product.name, mapOf("role" to "headline")))
)
experienceIds[product.id] = expId
}
}
fun onProductCellVisible(product: Product) {
experienceIds[product.id]?.let { expId ->
ContentAnalytics.trackExperienceView(expId, "feed.item.${product.id}")
}
}
}
Copied to your clipboard
import CommonCrypto
func computeExperienceId(texts: [String], assets: [String], ctas: [String]) -> String {
let content = (texts.sorted() + assets.sorted() + ctas.sorted()).joined(separator: "|")
let hash = content.data(using: .utf8)!.sha1Hex()
return "mobile-\(hash.prefix(12))"
}
Copied to your clipboard
import java.security.MessageDigest
fun computeExperienceId(texts: List<String>, assets: List<String>, ctas: List<String>): String {
val content = (texts.sorted() + assets.sorted() + ctas.sorted()).joinToString("|")
val hash = MessageDigest.getInstance("SHA-1")
.digest(content.toByteArray())
.joinToString("") { "%02x".format(it) }
return "mobile-${hash.take(12)}"
}
Copied to your clipboard
ContentAnalytics.trackExperienceView(experienceId: "exp-123")
let expId = ContentAnalytics.registerExperience(...)
ContentAnalytics.trackExperienceView(experienceId: expId)
Copied to your clipboard
ContentAnalytics.trackExperienceView("exp-123", "home")
val expId = ContentAnalytics.registerExperience(
assets = listOf(ContentItem("https://example.com/image.jpg", emptyMap())),
texts = listOf(ContentItem("Title", mapOf("role" to "headline")))
)
ContentAnalytics.trackExperienceView(expId, "home")
Copied to your clipboard
let expId = ContentAnalytics.registerExperience(
assets: [
ContentItem(value: "https://example.com/hero.jpg", styles: [:]),
ContentItem(value: "https://example.com/thumbnail.jpg", styles: [:])
],
texts: [ContentItem(value: "Summer Sale", styles: ["role": "headline"])]
)
ContentAnalytics.trackAssetView(assetURL: "https://example.com/hero.jpg")
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "homepage")
Copied to your clipboard
val expId = ContentAnalytics.registerExperience(
assets = listOf(
ContentItem("https://example.com/hero.jpg", emptyMap()),
ContentItem("https://example.com/thumbnail.jpg", emptyMap())
),
texts = listOf(ContentItem("Summer Sale", mapOf("role" to "headline")))
)
ContentAnalytics.trackAssetView("https://example.com/hero.jpg")
ContentAnalytics.trackExperienceView(expId, "homepage")
Copied to your clipboard
ContentAnalytics.trackAssetView(assetURL: "https://example.com/hero.jpg")
Copied to your clipboard
ContentAnalytics.trackAssetView("https://example.com/hero.jpg")
Copied to your clipboard
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "homepage.hero")
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "product.sidebar")
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "checkout.upsell")
Copied to your clipboard
ContentAnalytics.trackExperienceView(expId, "homepage.hero")
ContentAnalytics.trackExperienceView(expId, "product.sidebar")
ContentAnalytics.trackExperienceView(expId, "checkout.upsell")
Copied to your clipboard
ContentAnalytics.trackExperienceView(experienceId: expId)
Copied to your clipboard
ContentAnalytics.trackExperienceView(expId)
Copied to your clipboard
let heroImage = "https://example.com/hero.jpg"
ContentAnalytics.trackAssetView(assetURL: heroImage, assetLocation: "homepage")
ContentAnalytics.trackAssetView(assetURL: heroImage, assetLocation: "category.electronics")
ContentAnalytics.trackAssetView(assetURL: heroImage, assetLocation: "search.results")
Copied to your clipboard
val heroImage = "https://example.com/hero.jpg"
ContentAnalytics.trackAssetView(heroImage, "homepage")
ContentAnalytics.trackAssetView(heroImage, "category.electronics")
ContentAnalytics.trackAssetView(heroImage, "search.results")
Copied to your clipboard
let expId = ContentAnalytics.registerExperience(
assets: [ContentItem(value: "https://example.com/urgency-banner.jpg", styles: [:])],
texts: [
ContentItem(value: "Only 3 left!", styles: ["role": "headline"]),
ContentItem(value: "Order now before it's gone", styles: ["role": "body"])
]
)
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "product.detail")
Copied to your clipboard
val expId = ContentAnalytics.registerExperience(
assets = listOf(ContentItem("https://example.com/urgency-banner.jpg", emptyMap())),
texts = listOf(
ContentItem("Only 3 left!", mapOf("role" to "headline")),
ContentItem("Order now before it's gone", mapOf("role" to "body"))
)
)
ContentAnalytics.trackExperienceView(expId, "product.detail")
Copied to your clipboard
let loadStart = Date()
let loadTime = Date().timeIntervalSince(loadStart) * 1000
ContentAnalytics.trackAssetView(
assetURL: imageURL,
assetLocation: "product.gallery",
additionalData: [
"assetLoadTime": loadTime,
"assetSize": imageData.count,
"assetSource": "cdn"
]
)
Copied to your clipboard
val loadStart = System.currentTimeMillis()
val loadTime = System.currentTimeMillis() - loadStart
ContentAnalytics.trackAssetView(
assetURL = imageURL,
assetLocation = "product.gallery",
additionalData = mapOf(
"assetLoadTime" to loadTime,
"assetSize" to imageData.size,
"assetSource" to "cdn"
)
)
Copied to your clipboard
class ImageViewController {
var viewStartTime: Date?
var imageURL: String?
func viewDidAppear() {
viewStartTime = Date()
ContentAnalytics.trackAssetView(assetURL: imageURL!, assetLocation: "gallery")
}
func viewWillDisappear() {
guard let start = viewStartTime else { return }
let viewDuration = Date().timeIntervalSince(start) * 1000
ContentAnalytics.trackAssetClick(
assetURL: imageURL!,
assetLocation: "gallery",
additionalData: [
"assetViewDuration": viewDuration
]
)
}
}
Copied to your clipboard
class ImageFragment : Fragment() {
private var viewStartTime: Long = 0
private var imageURL: String? = null
override fun onResume() {
super.onResume()
viewStartTime = System.currentTimeMillis()
ContentAnalytics.trackAssetView(imageURL!!, "gallery")
}
override fun onPause() {
super.onPause()
val viewDuration = System.currentTimeMillis() - viewStartTime
ContentAnalytics.trackAssetClick(
assetURL = imageURL!!,
assetLocation = "gallery",
additionalData = mapOf(
"assetViewDuration" to viewDuration
)
)
}
}
Copied to your clipboard
class ProductCardView {
var expId: String?
var appearTime: Date?
func onAppear() {
appearTime = Date()
expId = ContentAnalytics.registerExperience(
assets: [ContentItem(value: product.imageURL, styles: [:])],
texts: [ContentItem(value: product.name, styles: ["role": "headline"])]
)
ContentAnalytics.trackExperienceView(
experienceId: expId!,
experienceLocation: "homepage.featured"
)
}
func onTap() {
let viewDuration = Date().timeIntervalSince(appearTime!) * 1000
ContentAnalytics.trackExperienceClick(
experienceId: expId!,
experienceLocation: "homepage.featured",
additionalData: [
"experienceViewDuration": viewDuration,
"scrollDepth": currentScrollPercent,
"interactionIndex": tapCount
]
)
}
}
Copied to your clipboard
@Composable
fun ProductCard(product: Product) {
var expId by remember { mutableStateOf<String?>(null) }
var appearTime by remember { mutableStateOf(0L) }
LaunchedEffect(product.id) {
appearTime = System.currentTimeMillis()
expId = ContentAnalytics.registerExperience(
assets = listOf(ContentItem(product.imageUrl, emptyMap())),
texts = listOf(ContentItem(product.name, mapOf("role" to "headline")))
)
ContentAnalytics.trackExperienceView(expId!!, "homepage.featured")
}
Column(
modifier = Modifier.clickable {
val viewDuration = System.currentTimeMillis() - appearTime
ContentAnalytics.trackExperienceClick(
experienceId = expId!!,
experienceLocation = "homepage.featured",
additionalData = mapOf(
"experienceViewDuration" to viewDuration,
"scrollDepth" to currentScrollPercent,
"interactionIndex" to tapCount
)
)
}
) {
}
}
Copied to your clipboard
import AEPAssurance
Assurance.startSession(url: assuranceDeepLink)
Copied to your clipboard
import com.adobe.marketing.mobile.Assurance
Assurance.startSession(assuranceDeepLink)
Copied to your clipboard
MobileCore.setLogLevel(.trace)
Copied to your clipboard
MobileCore.setLogLevel(LoggingMode.VERBOSE)
Copied to your clipboard
if experienceIds[productId] == nil {
experienceIds[productId] = ContentAnalytics.registerExperience(...)
}
Copied to your clipboard
if (!experienceIds.containsKey(productId)) {
experienceIds[productId] = ContentAnalytics.registerExperience(
assets = listOf(ContentItem(product.imageUrl, emptyMap())),
texts = listOf(ContentItem(product.name, mapOf("role" to "headline")))
)
}
Copied to your clipboard
class CarouselView: UIView {
private var experienceIds: [Int: String] = [:]
func configureSlide(_ slide: Slide, at index: Int) {
experienceIds[index] = ContentAnalytics.registerExperience(
assets: [ContentItem(value: slide.imageURL, styles: [:])],
texts: [ContentItem(value: slide.title, styles: ["role": "headline"])],
ctas: slide.ctaText.map { [ContentItem(value: $0, styles: ["enabled": true])] }
)
}
func slideDidAppear(at index: Int) {
guard let expId = experienceIds[index] else { return }
ContentAnalytics.trackExperienceView(experienceId: expId, experienceLocation: "home.carousel.\(index)")
}
func slideWasTapped(at index: Int) {
guard let expId = experienceIds[index] else { return }
ContentAnalytics.trackExperienceClick(experienceId: expId, experienceLocation: "home.carousel.\(index)")
}
}
Copied to your clipboard
class CarouselAdapter : RecyclerView.Adapter<CarouselViewHolder>() {
private val experienceIds = mutableMapOf<Int, String>()
override fun onBindViewHolder(holder: CarouselViewHolder, position: Int) {
val slide = slides[position]
experienceIds[position] = ContentAnalytics.registerExperience(
assets = listOf(ContentItem(slide.imageUrl, emptyMap())),
texts = listOf(ContentItem(slide.title, mapOf("role" to "headline"))),
ctas = slide.ctaText?.let { listOf(ContentItem(it, mapOf("enabled" to true))) }
)
holder.bind(slide)
}
override fun onViewAttachedToWindow(holder: CarouselViewHolder) {
experienceIds[holder.adapterPosition]?.let { expId ->
ContentAnalytics.trackExperienceView(expId, "home.carousel.${holder.adapterPosition}")
}
}
fun onSlideClicked(position: Int) {
experienceIds[position]?.let { expId ->
ContentAnalytics.trackExperienceClick(expId, "home.carousel.$position")
}
}
}
Copied to your clipboard
struct ProductCard: View {
let product: Product
@State private var expId: String?
var body: some View {
VStack {
AsyncImage(url: URL(string: product.imageURL))
Text(product.name)
Text(product.price)
}
.onAppear {
if expId == nil {
expId = ContentAnalytics.registerExperience(
assets: [ContentItem(value: product.imageURL, styles: [:])],
texts: [
ContentItem(value: product.name, styles: ["role": "headline"]),
ContentItem(value: product.price, styles: ["role": "price"])
]
)
}
if let id = expId {
ContentAnalytics.trackExperienceView(experienceId: id, experienceLocation: "catalog.product.\(product.id)")
}
}
.onTapGesture {
if let id = expId {
ContentAnalytics.trackExperienceClick(experienceId: id, experienceLocation: "catalog.product.\(product.id)")
}
}
}
}
Copied to your clipboard
@Composable
fun ProductCard(product: Product) {
var expId by remember { mutableStateOf<String?>(null) }
LaunchedEffect(product.id) {
expId = ContentAnalytics.registerExperience(
assets = listOf(ContentItem(product.imageUrl, emptyMap())),
texts = listOf(
ContentItem(product.name, mapOf("role" to "headline")),
ContentItem(product.price, mapOf("role" to "price"))
)
)
expId?.let {
ContentAnalytics.trackExperienceView(it, "catalog.product.${product.id}")
}
}
Column(
modifier = Modifier.clickable {
expId?.let {
ContentAnalytics.trackExperienceClick(it, "catalog.product.${product.id}")
}
}
) {
AsyncImage(model = product.imageUrl, contentDescription = null)
Text(product.name)
Text(product.price)
}
}
Copied to your clipboard
struct TrackedExperience<Content: View>: View {
let assets: [ContentItem]
let texts: [ContentItem]
let location: String
let content: Content
@State private var expId: String?
init(
assets: [ContentItem],
texts: [ContentItem],
location: String,
@ViewBuilder content: () -> Content
) {
self.assets = assets
self.texts = texts
self.location = location
self.content = content()
}
var body: some View {
content
.onAppear {
if expId == nil {
expId = ContentAnalytics.registerExperience(assets: assets, texts: texts)
}
if let id = expId {
ContentAnalytics.trackExperienceView(experienceId: id, experienceLocation: location)
}
}
.onTapGesture {
if let id = expId {
ContentAnalytics.trackExperienceClick(experienceId: id, experienceLocation: location)
}
}
}
}
TrackedExperience(
assets: [ContentItem(value: product.imageURL, styles: [:])],
texts: [ContentItem(value: product.name, styles: ["role": "headline"])],
location: "product.\(product.id)"
) {
ProductCardView(product: product)
}
Copied to your clipboard
@Composable
fun TrackedExperience(
assets: List<ContentItem>,
texts: List<ContentItem>,
location: String,
onClick: (() -> Unit)? = null,
content: @Composable () -> Unit
) {
var expId by remember { mutableStateOf<String?>(null) }
LaunchedEffect(location) {
expId = ContentAnalytics.registerExperience(assets = assets, texts = texts)
expId?.let { ContentAnalytics.trackExperienceView(it, location) }
}
Box(
modifier = Modifier.clickable {
expId?.let { ContentAnalytics.trackExperienceClick(it, location) }
onClick?.invoke()
}
) {
content()
}
}
TrackedExperience(
assets = listOf(ContentItem(product.imageUrl, emptyMap())),
texts = listOf(ContentItem(product.name, mapOf("role" to "headline"))),
location = "product.${product.id}"
) {
ProductCardView(product)
}