### Start Metro Server for Example App
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Starts the Metro bundler, which is necessary for running the example application. This command is used to serve the JavaScript code to the example app during development.
```sh
yarn example start
```
--------------------------------
### Start Metro Server for React Native
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/example/README.md
Starts the Metro bundler, which is essential for running React Native applications. This command should be executed from the root of the React Native project.
```bash
# using npm
npm start
# OR using Yarn
yarn start
```
--------------------------------
### Install Project Dependencies with Yarn
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Installs all project dependencies required for the monorepo, leveraging Yarn workspaces. This is the initial setup step for development.
```sh
yarn
```
--------------------------------
### Install react-native-skadnetwork using Yarn or npm
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Instructions for installing the SKAdNetwork package using either Yarn or npm package managers. This is the first step before proceeding with iOS setup.
```bash
# Install the package
yarn add react-native-skadnetwork
# or
npm install react-native-skadnetwork
# iOS setup - navigate to ios directory and install pods
cd ios
pod install
cd ..
```
--------------------------------
### Run Example App on iOS
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Builds and runs the example application on an connected iOS device or simulator. This command is essential for testing library changes on iOS.
```sh
yarn example ios
```
--------------------------------
### Run Example App on Android
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Builds and runs the example application on an connected Android device or emulator. This command is essential for testing library changes on Android.
```sh
yarn example android
```
--------------------------------
### Basic SKAdNetwork initialization in React Native
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
A basic implementation example in JavaScript to initialize SKAdNetwork tracking on app launch using the 'react-native-skadnetwork' library. It logs an 'install' event (event code 5).
```javascript
// Basic implementation in your app's entry point
import React, { useEffect } from 'react';
import { logEventSKAdNetwork } from 'react-native-skadnetwork';
function App() {
useEffect(() => {
// Initialize SKAdNetwork on app launch
const initializeSKAd = async () => {
try {
await logEventSKAdNetwork(5); // Track install
} catch (error) {
console.error('SKAdNetwork initialization failed:', error);
}
};
initializeSKAd();
}, []);
return (
// Your app components
);
}
export default App;
```
--------------------------------
### React Native SKAdNetwork Component Integration
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Demonstrates a complete example of integrating SKAdNetwork tracking within a React Native application. It covers logging initial install events, user signups, purchases (with SKAdNetwork 4 parameters), and ad views. Requires the 'react-native-skadnetwork' library.
```javascript
import React, { useEffect, useState } from 'react';
import { StyleSheet, View, Text, Button, Alert } from 'react-native';
import { logEventSKAdNetwork } from 'react-native-skadnetwork';
const events = {
SIGNUP: 0,
LEVEL_1: 1,
LEVEL_2: 2,
AD_VIEW: 3,
PURCHASE: 4,
INSTALL: 5,
};
export default function App() {
const [lastEvent, setLastEvent] = useState(null);
// Log initial install event
useEffect(() => {
const trackInstall = async () => {
try {
await logEventSKAdNetwork(events.INSTALL);
setLastEvent('INSTALL');
console.log('Install event tracked');
} catch (error) {
console.error('Failed to track install:', error);
}
};
trackInstall();
}, []);
const handleUserSignup = async () => {
try {
// Perform signup logic
await logEventSKAdNetwork(events.SIGNUP);
setLastEvent('SIGNUP');
Alert.alert('Success', 'Signup tracked');
} catch (error) {
Alert.alert('Error', 'Failed to track signup');
}
};
const handlePurchase = async () => {
try {
// Perform purchase logic
// Use SKAN 4 parameters for high-value conversion
await logEventSKAdNetwork(events.PURCHASE, 2, true);
setLastEvent('PURCHASE');
Alert.alert('Success', 'Purchase tracked');
} catch (error) {
Alert.alert('Error', 'Failed to track purchase');
}
};
const handleAdView = async () => {
try {
await logEventSKAdNetwork(events.AD_VIEW, 0, false);
setLastEvent('AD_VIEW');
} catch (error) {
console.error('Failed to track ad view:', error);
}
};
return (
SKAdNetwork IntegrationLast Event: {lastEvent || 'None'}
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
padding: 20,
},
title: {
fontSize: 20,
fontWeight: 'bold',
marginBottom: 20,
},
});
```
--------------------------------
### Run React Native App on iOS
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/example/README.md
Builds and runs the React Native application on an iOS simulator or device. Ensure Metro Server is running in a separate terminal. This command is executed from the project root.
```bash
# using npm
npm run ios
# OR using Yarn
yarn ios
```
--------------------------------
### Run React Native App on Android
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/example/README.md
Builds and runs the React Native application on an Android emulator or device. Ensure Metro Server is running in a separate terminal. This command is executed from the project root.
```bash
# using npm
npm run android
# OR using Yarn
yarn android
```
--------------------------------
### Install react-native-skadnetwork with Yarn or NPM
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/README.md
Instructions for installing the react-native-skadnetwork module using either Yarn or NPM package managers. This is the first step to integrate SKAdNetwork features into your React Native project.
```sh
yarn add react-native-skadnetwork
```
```sh
npm install react-native-skadnetwork
```
--------------------------------
### SKAdNetwork Event Model and Conversion Value Calculation
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Explains the 6-bit system used by SKAdNetwork for tracking multiple events. Demonstrates how each event maps to a bit position and how to calculate the resulting conversion value. Provides examples of logging individual events and a manual method for combining multiple events.
```javascript
import { logEventSKAdNetwork } from 'react-native-skadnetwork';
// The module uses a 6-bit system where each event maps to a bit position
// Conversion value = sum of (bit_value * 2^position)
const events = {
SIGNUP: 0, // bit 0: value = 2^0 = 1
LEVEL_1: 1, // bit 1: value = 2^1 = 2
LEVEL_2: 2, // bit 2: value = 2^2 = 4
AD_VIEW: 3, // bit 3: value = 2^3 = 8
PURCHASE: 4, // bit 4: value = 2^4 = 16
INSTALL: 5, // bit 5: value = 2^5 = 32
};
// Example: Logging SIGNUP
await logEventSKAdNetwork(events.SIGNUP);
// Bit array: [1, 0, 0, 0, 0, 0]
// Conversion value: 1 * 2^0 = 1
// Example: Logging PURCHASE
await logEventSKAdNetwork(events.PURCHASE);
// Bit array: [0, 0, 0, 0, 1, 0]
// Conversion value: 1 * 2^4 = 16
// Example: Logging INSTALL
await logEventSKAdNetwork(events.INSTALL);
// Bit array: [0, 0, 0, 0, 0, 1]
// Conversion value: 1 * 2^5 = 32
// Note: Each call sets only one bit; previous values are overwritten
// To track multiple events, implement your own bit management:
let conversionValue = 0;
conversionValue |= (1 << events.SIGNUP); // Add SIGNUP
conversionValue |= (1 << events.PURCHASE); // Add PURCHASE
// Result: bits 0 and 4 are set, conversion value = 17
```
--------------------------------
### Log SKAdNetwork Event with Conversion Value
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Logs a conversion event to SKAdNetwork and updates the conversion value using a bit-based system. Supports basic events and SKAN 4 parameters (coarse value, lock window) on compatible iOS versions. Includes error handling examples.
```javascript
import { logEventSKAdNetwork } from 'react-native-skadnetwork';
// Define event constants (0-5 mapping to bit positions)
const events = {
SIGNUP: 0,
LEVEL_1: 1,
LEVEL_2: 2,
AD_VIEW: 3,
PURCHASE: 4,
INSTALL: 5,
};
// Basic usage: Log a purchase event
// This sets bit 4 to 1, resulting in conversion value 16
await logEventSKAdNetwork(events.PURCHASE);
// Log a signup event
// This sets bit 0 to 1, resulting in conversion value 1
await logEventSKAdNetwork(events.SIGNUP);
// Advanced usage with SKAN 4 parameters (iOS 16.1+)
// coarseValue: 0 (Low), 1 (Medium), 2 (High)
// lockWindow: true to lock the conversion window
await logEventSKAdNetwork(events.PURCHASE, 2, true);
// Error handling example
try {
await logEventSKAdNetwork(events.LEVEL_1);
console.log('Conversion value updated successfully');
} catch (error) {
console.error('Failed to update conversion value:', error);
}
```
--------------------------------
### Native Module: Set SKAdNetwork Conversion Value Directly
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Provides direct access to the native SKAdNetwork module for setting conversion values. Supports fine-grained control over 'fineValue' (0-63), 'coarseValue' (iOS 16.1+), and 'lockWindow' parameters. Includes examples for different iOS versions and error scenarios.
```javascript
import { NativeModules } from 'react-native';
const { SKAdNetworkModule } = NativeModules;
// Direct conversion value setting
// fineValue: 0-63 (6-bit conversion value)
// coarseValue: 0 (Low), 1 (Medium), 2 (High) - iOS 16.1+ only
// lockWindow: boolean to lock the conversion window
try {
const result = await SKAdNetworkModule.setConversionValue(16, 2, false);
console.log('Success:', result); // Output: true
} catch (error) {
console.error('Error:', error);
// Error examples:
// - "Fine value must be between 0 and 63"
// - "Coarse value must be between 0 and 2"
// - "This iOS version is not compatible with SKAdNetwork"
}
// iOS 14.0-15.3: Only fineValue is used
await SKAdNetworkModule.setConversionValue(32, 0, false);
// iOS 15.4+: Supports completion handler
await SKAdNetworkModule.setConversionValue(8, 0, false);
// iOS 16.1+: Full SKAN 4 support with coarse value and lock window
await SKAdNetworkModule.setConversionValue(16, 1, true);
```
--------------------------------
### Publish New Versions with Release-it
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Initiates the process of publishing a new version of the library to npm using release-it. This script automates version bumping, tagging, and release creation.
```sh
yarn release
```
--------------------------------
### Run Unit Tests with Jest
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Executes all unit tests defined in the project using the Jest testing framework. This command is crucial for verifying the correctness of code changes.
```sh
yarn test
```
--------------------------------
### Configure SKAdNetwork IDs in iOS Info.plist
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Shows the XML structure for adding SKAdNetwork identifiers to the `Info.plist` file in an iOS project. This is crucial for enabling SKAdNetwork attribution.
```xml
SKAdNetworkItemsSKAdNetworkIdentifiercstr6suwn9.skadnetworkSKAdNetworkIdentifier4fzdc2evr5.skadnetwork
```
--------------------------------
### Manually add SKAdNetwork pod to iOS Podfile
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Provides Ruby code for manually adding the SKAdNetwork pod to an iOS project's Podfile if automatic linking fails. This ensures the native SKAdNetwork extension is included in the iOS build.
```ruby
# If automatic linking fails, manually add to ios/Podfile
target 'YourAppName' do
# ... other pods
pod 'SKAdNetworkExtension', :path => '../node_modules/react-native-skadnetwork'
end
```
--------------------------------
### Lint Project Files with ESLint
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Lints the project's code using ESLint to enforce code style and catch potential issues. This command helps maintain code quality and consistency across the project.
```sh
yarn lint
```
--------------------------------
### Log SKAdNetwork Events in React Native
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/README.md
Demonstrates how to log conversion events using the `logEventSKAdNetwork` function from the react-native-skadnetwork module. It shows logging a predefined event (PURCHASE) and logging a raw conversion value.
```javascript
import { logEventSKAdNetwork } from 'react-native-skadnetwork';
const events = {
SIGNUP: 0,
LEVEL_1: 1,
LEVEL_2: 2,
AD_VIEW: 3,
PURCHASE: 4,
INSTALL: 5,
};
logEventSKAdNetwork(events.PURCHASE); // conversion value = 16 / byte value = 0, 0, 0, 0, 1, 0
// or send identification manually
logEventSKAdNetwork(0); // conversion value = 1 / byte value = 1, 0, 0, 0, 0, 0
```
--------------------------------
### Version-Specific SKAdNetwork Purchase Event Tracking (JavaScript)
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
This JavaScript function demonstrates how to track purchase events using SKAdNetwork, adapting the tracking parameters based on the iOS version. It leverages SKAN 4 features like coarse value and lock window for newer iOS versions (16.1+) and falls back to basic or registration-only modes for older versions. It uses 'react-native' for platform checks and 'react-native-skadnetwork' for event logging.
```javascript
// Usage with version-specific features
const trackPurchaseEvent = async () => {
const events = { PURCHASE: 4 };
// Check iOS version for SKAN 4 features
const systemVersion = parseFloat(Platform.Version);
if (systemVersion >= 16.1) {
// Use SKAN 4 features: coarse value and lock window
await trackEventSafely(events.PURCHASE, 2, true);
console.log('SKAN 4 tracking with coarse value');
} else if (systemVersion >= 15.4) {
// Use SKAN 3 with completion handler
await trackEventSafely(events.PURCHASE, 0, false);
console.log('SKAN 3 tracking');
} else if (systemVersion >= 14.0) {
// Basic SKAN 3 support
await trackEventSafely(events.PURCHASE);
console.log('Basic SKAN tracking');
} else {
// Only registration available
console.log('Limited SKAdNetwork support');
await trackEventSafely(0); // Register only
}
};
```
--------------------------------
### Manually update Podfile for iOS integration
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/README.md
A manual step to update the iOS Podfile for the SKAdNetworkExtension module if automatic linking fails. This ensures the native iOS dependencies are correctly managed by CocoaPods for the React Native project.
```ruby
pod 'SKAdNetworkExtension', :path => '../node_modules/SKAdNetworkExtension'
```
--------------------------------
### Fix Formatting Errors with ESLint
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Automatically fixes code formatting errors detected by ESLint. This command should be run to ensure code style compliance before committing changes.
```sh
yarn lint --fix
```
--------------------------------
### Typecheck Project Files with TypeScript
Source: https://github.com/bejutassle/react-native-skadnetwork/blob/master/CONTRIBUTING.md
Performs a full type check of the project's TypeScript files. This ensures code adheres to defined types and helps catch potential type-related errors before committing.
```sh
yarn typecheck
```
--------------------------------
### Safe SKAdNetwork Event Tracking with Error Handling (JavaScript)
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
This JavaScript function safely tracks SKAdNetwork events, handling potential errors related to invalid values, unsupported versions, or update failures. It ensures that the tracking logic only runs on iOS and logs appropriate messages for success or failure. Dependencies include 'react-native' and 'react-native-skadnetwork'.
```javascript
import { Platform } from 'react-native';
import { logEventSKAdNetwork } from 'react-native-skadnetwork';
const trackEventSafely = async (event, coarseValue = 0, lockWindow = false) => {
// Only works on iOS
if (Platform.OS !== 'ios') {
console.log('SKAdNetwork is only available on iOS');
return;
}
try {
await logEventSKAdNetwork(event, coarseValue, lockWindow);
console.log(`Event ${event} tracked successfully`);
return { success: true };
} catch (error) {
// Handle specific error types
if (error.code === 'invalid_fine_value') {
console.error('Invalid conversion value (must be 0-63):', error.message);
} else if (error.code === 'invalid_coarse_value') {
console.error('Invalid coarse value (must be 0-2):', error.message);
} else if (error.code === 'version_not_supported') {
console.error('iOS version not supported (requires iOS 11.3+)');
} else if (error.code === 'update_error') {
console.error('SKAdNetwork update failed:', error.message);
} else {
console.error('Unknown error:', error);
}
return { success: false, error };
}
};
```
--------------------------------
### Native Module: Set Conversion Value
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Provides low-level access to the native SKAdNetwork module for directly setting the conversion value. This method is typically called internally by `logEventSKAdNetwork` but can be used for more granular control.
```APIDOC
## POST /setConversionValue
### Description
This is a low-level native module method that allows direct control over setting the SKAdNetwork conversion value. It is generally called internally by the higher-level `logEventSKAdNetwork` function but can be accessed for advanced use cases. It supports different parameter sets based on the iOS version.
### Method
POST
### Endpoint
NativeModules.SKAdNetworkModule.setConversionValue
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **fineValue** (number) - Required - The 6-bit conversion value (0-63).
- **coarseValue** (number) - Optional - For iOS 16.1+, indicates the coarse conversion value: 0 (Low), 1 (Medium), 2 (High).
- **lockWindow** (boolean) - Optional - For iOS 16.1+, a boolean to lock the conversion window.
### Request Example
```javascript
import { NativeModules } from 'react-native';
const { SKAdNetworkModule } = NativeModules;
// iOS 16.1+ with full SKAN 4 support
try {
const result = await SKAdNetworkModule.setConversionValue(16, 2, false); // fine=16, coarse=High, lock=false
console.log('Success:', result);
} catch (error) {
console.error('Error:', error);
}
// iOS 15.4+ supports completion handler (coarseValue and lockWindow are ignored)
await SKAdNetworkModule.setConversionValue(8, 0, false); // fine=8
// iOS 14.0-15.3: Only fineValue is used
await SKAdNetworkModule.setConversionValue(32, 0, false); // fine=32
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the conversion value was set successfully.
#### Response Example
```json
{
"success": true
}
```
#### Error Handling
Errors may occur if the provided values are out of range (e.g., `fineValue` not between 0-63) or if the iOS version does not support the requested parameters.
```
--------------------------------
### Log Conversion Event
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
Logs a conversion event to SKAdNetwork and updates the conversion value based on the event identifier. Supports SKAN 3 and SKAN 4 parameters.
```APIDOC
## POST /logEventSKAdNetwork
### Description
Logs a conversion event to SKAdNetwork and updates the conversion value based on the event identifier. This function supports both basic event logging and advanced SKAN 4 parameters for iOS 16.1+.
### Method
POST
### Endpoint
/logEventSKAdNetwork
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **eventIdentifier** (number) - Required - An integer representing the event, typically mapped to a bit position (0-5).
- **coarseValue** (number) - Optional - For SKAN 4 (iOS 16.1+), indicates the coarse conversion value: 0 (Low), 1 (Medium), 2 (High).
- **lockWindow** (boolean) - Optional - For SKAN 4 (iOS 16.1+), a boolean to lock the conversion window after this event.
### Request Example
```javascript
import { logEventSKAdNetwork } from 'react-native-skadnetwork';
const events = {
SIGNUP: 0,
LEVEL_1: 1,
LEVEL_2: 2,
AD_VIEW: 3,
PURCHASE: 4,
INSTALL: 5,
};
// Log a purchase event (sets bit 4, conversion value 16)
await logEventSKAdNetwork(events.PURCHASE);
// Log a signup event (sets bit 0, conversion value 1)
await logEventSKAdNetwork(events.SIGNUP);
// Advanced usage with SKAN 4 parameters (iOS 16.1+)
await logEventSKAdNetwork(events.PURCHASE, 2, true); // High coarse value, lock window
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the event logging was successful.
#### Response Example
```json
{
"success": true
}
```
#### Error Handling
The function may throw errors for invalid parameters or unsupported iOS versions. Use try-catch blocks for robust error handling.
```
--------------------------------
### Retry Logic for Failed SKAdNetwork Event Tracking (JavaScript)
Source: https://context7.com/bejutassle/react-native-skadnetwork/llms.txt
This JavaScript function implements a retry mechanism for tracking SKAdNetwork events that might fail initially. It attempts to track an event multiple times with increasing delays between retries, up to a specified maximum. This is useful for handling transient network issues or temporary service unavailability. It depends on the 'trackEventSafely' function.
```javascript
// Example: Retry logic for failed updates
const trackEventWithRetry = async (event, maxRetries = 3) => {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
const result = await trackEventSafely(event);
if (result.success) {
return true;
}
console.log(`Attempt ${attempt} failed, retrying...`);
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
}
console.error('Failed to track event after all retries');
return false;
};
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.