Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ jobs:
steps:
- name: Checkout Branch
uses: actions/checkout@v6.0.2
- name: "Install JDK 11"
- name: "Install JDK 17"
uses: actions/setup-java@v5
with:
distribution: zulu
java-version: 11
java-version: 17
- name: Install NPM
uses: actions/setup-node@v6
- name: NPM Build
Expand Down
2 changes: 1 addition & 1 deletion Kits/Rokt/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="mParticle-Rokt" spec="8.3.0" />
<pod name="mParticle-Rokt" spec="~> 9.0" />
</pods>
</podspec>
</platform>
Expand Down
23 changes: 23 additions & 0 deletions Kits/RoktPaymentExtension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@mparticle/cordova-rokt-payment-extension",
Comment thread
cursor[bot] marked this conversation as resolved.
"version": "3.0.0",
"description": "Adds Rokt payment extension support to your Cordova project",
"homepage": "https://www.mparticle.com",
"repository": {
"type": "git",
"url": "https://github.com/mParticle/cordova-plugin-mparticle",
"directory": "Kits/RoktPaymentExtension"
},
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"provenance": true,
"registry": "https://registry.npmjs.org/"
},
"cordova": {
"id": "@mparticle/cordova-rokt-payment-extension",
"platforms": [
"ios"
]
}
}
17 changes: 17 additions & 0 deletions Kits/RoktPaymentExtension/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
id="@mparticle/cordova-rokt-payment-extension"
version="3.0.0">
<name>MParticle Rokt Payment Extension Kit</name>
<description>Adds Rokt payment extension support to your Cordova project</description>
<platform name="ios">
<podspec>
<config>
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="RoktPaymentExtension" spec="~> 1.0" />
</pods>
</podspec>
</platform>
</plugin>
99 changes: 98 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cordova plugin add @mparticle/cordova-sdk
**Install the SDK** using CocoaPods:

```bash
$ # Update your Podfile to depend on 'mParticle-Apple-SDK' version 8.5.2 or later
$ # Update your Podfile to depend on 'mParticle-Apple-SDK' version 9.0 or later
$ pod install
```

Expand Down Expand Up @@ -264,6 +264,103 @@ identity.modify(request, function (userId) => {
});
```

## Rokt

### Installation

Add the Rokt kit with the Cordova CLI:

```bash
cordova plugin add @mparticle/cordova-rokt-kit
```

Or declare it in your `config.xml`:

```xml
<plugin name="@mparticle/cordova-rokt-kit" spec="~> 3.0" />
```

### Select Placements

Display a Rokt overlay placement on your confirmation or thank-you page:

```js
var attributes = {
'email': 'j.smith@example.com',
'firstname': 'Jenny',
'lastname': 'Smith',
'confirmationref': '54321',
'country': 'US'
};

mparticle.Rokt.selectPlacements('YourPlacementIdentifier', attributes);
```

You can optionally pass a configuration object:

```js
var config = {
colorMode: mparticle.Rokt.ColorMode.SYSTEM, // LIGHT, DARK, or SYSTEM
cacheConfig: {
cacheDurationInSeconds: 5400,
cacheAttributes: {}
}
};

mparticle.Rokt.selectPlacements('YourPlacementIdentifier', attributes, config);
```

### Shoppable Ads

Shoppable Ads enable post-purchase upsell offers with instant checkout. Currently supported on **iOS only**.

#### 1. Add the payment extension

With the Cordova CLI:

```bash
cordova plugin add @mparticle/cordova-rokt-payment-extension
```

Or declare it in your `config.xml`:

```xml
<plugin name="@mparticle/cordova-rokt-payment-extension" spec="^3.0.0" />
```

#### 2. Register the payment extension

The `RoktPaymentExtension` must be registered in your native iOS code after SDK initialization and before calling `selectShoppableAds`.

Since `RoktPaymentExtension` is Swift-only, ObjC apps need a bridging class. See `example/platform_overrides/ios/RoktPaymentSetup.swift` for the wrapper, then call from your AppDelegate:

```objc
#import "YourApp-Swift.h"

[RoktPaymentSetup registerPaymentExtensionWithMerchantId:@"merchant.com.yourapp.rokt"];
```

#### 3. Display Shoppable Ads

```js
var attributes = {
'email': 'j.smith@example.com',
'firstname': 'Jenny',
'lastname': 'Smith',
'confirmationref': 'ORD-8829-XK2',
'amount': '52.25',
'currency': 'USD',
'paymenttype': 'visa',
'shippingaddress1': '123 Main St',
'shippingcity': 'Brooklyn',
'shippingstate': 'NY',
'shippingzipcode': '11201',
'shippingcountry': 'US'
};

mparticle.Rokt.selectShoppableAds('YourPlacementIdentifier', attributes);
```

# License

Apache 2.0
5 changes: 3 additions & 2 deletions example/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<preference name="deployment-target" value="12.0" />
<preference name="pods_ios_min_version" value="12.0" />
<preference name="deployment-target" value="16.0" />
<preference name="pods_ios_min_version" value="16.0" />
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
Expand All @@ -30,4 +30,5 @@
<hook type="after_platform_add" src="hooks/after_platform_add/010_copy_platform_specific_files.js" />
<plugin name="@mparticle/cordova-sdk" spec="../plugin" />
<plugin name="@mparticle/cordova-rokt-kit" spec="../Kits/Rokt" />
<plugin name="@mparticle/cordova-rokt-payment-extension" spec="../Kits/RoktPaymentExtension" />
</widget>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var shell = require('child_process');
module.exports = function(context) {
// Get platform from context
var platform = context.opts.platforms[0];

function ensureDirectoryExistence(filePath) {
var dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
Expand All @@ -16,35 +16,64 @@ module.exports = function(context) {
fs.mkdirSync(dirname, { recursive: true });
}

if (platform === 'android') {
// Copy MainActivity.java
var srcFile = path.join(context.opts.projectRoot, 'platform_overrides', 'android', 'MainActivity.java');
var destFile = path.join(context.opts.projectRoot, 'platforms', 'android', 'app', 'src', 'main', 'java', 'com', 'mparticle', 'example', 'MainActivity.java');

if (fs.existsSync(srcFile)) {
function copyFile(srcRelative, destRelative, label) {
var src = path.join(context.opts.projectRoot, srcRelative);
var dest = path.join(context.opts.projectRoot, destRelative);
if (fs.existsSync(src)) {
try {
ensureDirectoryExistence(destFile);
fs.copyFileSync(srcFile, destFile);
console.log('Copied custom MainActivity.java');
ensureDirectoryExistence(dest);
fs.copyFileSync(src, dest);
console.log('Copied ' + label);
} catch (err) {
console.error('Error copying MainActivity.java:', err);
console.error('Error copying ' + label + ':', err);
process.exitCode = 1;
}
}
}

if (platform === 'android') {
copyFile(
path.join('platform_overrides', 'android', 'MainActivity.java'),
path.join('platforms', 'android', 'app', 'src', 'main', 'java', 'com', 'mparticle', 'example', 'MainActivity.java'),
'custom MainActivity.java'
);
} else if (platform === 'ios') {
// Copy AppDelegate.m
var srcFile = path.join(context.opts.projectRoot, 'platform_overrides', 'ios', 'AppDelegate.m');
var destFile = path.join(context.opts.projectRoot, 'platforms', 'ios', 'MParticleExample', 'AppDelegate.m');

if (fs.existsSync(srcFile)) {
copyFile(
path.join('platform_overrides', 'ios', 'AppDelegate.m'),
path.join('platforms', 'ios', 'MParticleExample', 'AppDelegate.m'),
'custom AppDelegate.m'
);

copyFile(
path.join('platform_overrides', 'ios', 'RoktPaymentSetup.swift'),
path.join('platforms', 'ios', 'MParticleExample', 'RoktPaymentSetup.swift'),
'RoktPaymentSetup.swift'
);

// Create bridging header for Swift/ObjC interop
var bridgingHeaderPath = path.join(context.opts.projectRoot, 'platforms', 'ios', 'MParticleExample', 'MParticleExample-Bridging-Header.h');
if (!fs.existsSync(bridgingHeaderPath)) {
try {
ensureDirectoryExistence(destFile);
fs.copyFileSync(srcFile, destFile);
console.log('Copied custom AppDelegate.m');
fs.writeFileSync(bridgingHeaderPath, '// Bridging header for Swift/ObjC interop\n');
console.log('Created bridging header');
} catch (err) {
console.error('Error copying AppDelegate.m:', err);
console.error('Error creating bridging header:', err);
process.exitCode = 1;
}
}

// NOTE: RoktPaymentExtension pod is added automatically by the
// @mparticle/cordova-rokt-payment-extension declared in config.xml.
// If using a kit, no manual Podfile manipulation is needed here.

// Add Swift file to Xcode project and configure Swift settings
var iosPath = path.join(context.opts.projectRoot, 'platforms', 'ios');
var configureXcodeScript = path.join(context.opts.projectRoot, 'hooks', 'after_platform_add', 'configure_xcode_swift.rb');
try {
shell.execSync('cd ' + iosPath + ' && ruby ' + configureXcodeScript, { stdio: 'inherit' });
} catch (err) {
console.error('Error configuring Xcode project for Swift:', err);
process.exitCode = 1;
}
}
};
16 changes: 16 additions & 0 deletions example/hooks/after_platform_add/configure_xcode_swift.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'xcodeproj'

proj = Xcodeproj::Project.open('MParticleExample.xcodeproj')
target = proj.targets.find { |t| t.name == 'MParticleExample' }
group = proj.main_group.find_subpath('MParticleExample', false)

swift_ref = group.new_file('RoktPaymentSetup.swift')
target.source_build_phase.add_file_reference(swift_ref)

target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '5.0'
config.build_settings['SWIFT_OBJC_BRIDGING_HEADER'] = 'MParticleExample/MParticleExample-Bridging-Header.h'
end

proj.save
puts 'Configured Xcode project for Swift/Shoppable Ads'
Loading
Loading