MCPcopy Create free account
hub / github.com/Iterable/react-native-sdk / Commerce

Function Commerce

example/src/components/Commerce/Commerce.tsx:9–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import styles from './Commerce.styles';
8
9export const Commerce = () => {
10 const handleClick = (item: CommerceItem) => {
11 const purchasedItem = new IterableCommerceItem(
12 item.id,
13 item.name,
14 item.price,
15 1
16 );
17 const totalPrice = item.price;
18 const purchaseItems = [purchasedItem];
19 const dataFields = null;
20
21 Iterable.trackPurchase(totalPrice, purchaseItems, dataFields);
22
23 console.group('Purchase tracked with the following arguments:');
24 console.log('Total price:', totalPrice);
25 console.log('Purchase items:', [...purchaseItems]);
26 console.log('Data fields:', dataFields);
27 console.groupEnd();
28
29 Alert.alert(
30 `Tracked purchase: ${item.name}, $${item.price}`,
31 'Check logs for output'
32 );
33 };
34
35 return (
36 <SafeAreaView>
37 <ScrollView>
38 <View style={styles.container}>
39 <Text style={styles.title}>Commerce</Text>
40 <Text style={styles.subtitle}>
41 Purchase will be tracked when &quot;Buy&quot; is clicked. See logs for
42 output.
43 </Text>
44 {items.map((item) => (
45 <View key={item.id} style={styles.cardContainer}>
46 <View style={styles.infoContainer}>
47 <View style={styles.imageContainer}>
48 <Image source={item.icon} style={styles.cardImage} />
49 </View>
50 <View style={styles.textContainer}>
51 <Text style={styles.cardTitle}>{item.name}</Text>
52 <Text style={styles.cardSubtitle}>{item.subtitle}</Text>
53 <Text style={styles.price}>${item.price}</Text>
54 <Pressable
55 style={styles.button}
56 onPress={() => handleClick(item)}
57 >
58 <Text style={styles.buttonText}>Buy</Text>
59 </Pressable>
60 </View>
61 </View>
62 </View>
63 ))}
64 </View>
65 </ScrollView>
66 </SafeAreaView>

Callers

nothing calls this directly

Calls 1

handleClickFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…