Skip to content

Commit

Permalink
Merge pull request #39 from OutSystems/development
Browse files Browse the repository at this point in the history
Prepare `main` for `5.0.0-OS13`
  • Loading branch information
OS-ricardomoreirasilva authored Jul 23, 2024
2 parents 33d1c74 + 069dd6c commit a35cc38
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

The changes documented here do not include those from the original repository.

## 5.0.0-OS13
- Fix: Make `ANALYTICS_COLLECTION_ENABLED` configurable (https://outsystemsrd.atlassian.net/browse/RMET-3503).

## 5.0.0-OS12
- Chore: Update `FirebaseAnalytics` iOS pod to version `10.23.0` (https://outsystemsrd.atlassian.net/browse/RMET-3274).

Expand Down
45 changes: 45 additions & 0 deletions hooks/android/androidCopyPreferences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const path = require('path');
const fs = require('fs');
const { ConfigParser } = require('cordova-common');
const xml2js = require('xml2js');
const q = require('q');

module.exports = function (context) {
let projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
let configXML = path.join(projectRoot, 'config.xml');
let configParser = new ConfigParser(configXML);

let manifestPath = path.join(projectRoot, 'platforms/android/app/src/main/AndroidManifest.xml');

let defer = q.defer();

let collectionEnabled = configParser.getGlobalPreference("ANALYTICS_COLLECTION_ENABLED");
if (collectionEnabled.toLowerCase() == 'false') {
let parser = new xml2js.Parser();
parser.parseStringPromise(fs.readFileSync(manifestPath, 'utf8')).then((result) => {
let metadata = result.manifest.application[0]['meta-data'];
metadata.push({
'$': {
'android:name': 'firebase_analytics_collection_enabled',
'android:value': 'false'
}
})

let builder = new xml2js.Builder();
let xml = builder.buildObject(result);

fs.writeFileSync(manifestPath, xml, (err) => {
throw new Error (`OUTSYSTEMS_PLUGIN_ERROR: Something went wrong while saving the AndroidManifest.xml file. Please check the logs for more information.`);
});

defer.resolve();
})
.catch((err) => {
throw new Error (`OUTSYSTEMS_PLUGIN_ERROR: Something went wrong while parsing the AndroidManifest.xml file. Please check the logs for more information.`);
});
} else {
defer.resolve();
}

return defer.promise;
};
33 changes: 18 additions & 15 deletions hooks/ios/iOSCopyPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ const plist = require('plist');
const { ConfigParser } = require('cordova-common');

module.exports = function (context) {
var projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
var configXML = path.join(projectRoot, 'config.xml');
var configParser = new ConfigParser(configXML);
var enableAppTracking = configParser.getPlatformPreference("EnableAppTrackingTransparencyPrompt", "ios");

var appNamePath = path.join(projectRoot, 'config.xml');
var appNameParser = new ConfigParser(appNamePath);
var appName = appNameParser.name();
var infoPlistPath = path.join(projectRoot, 'platforms/ios/' + appName + '/'+ appName +'-info.plist');
var obj = plist.parse(fs.readFileSync(infoPlistPath, 'utf8'));
let projectRoot = context.opts.cordova.project ? context.opts.cordova.project.root : context.opts.projectRoot;
let configXML = path.join(projectRoot, 'config.xml');
let configParser = new ConfigParser(configXML);

let appName = configParser.name();
let infoPlistPath = path.join(projectRoot, 'platforms/ios/' + appName + '/'+ appName +'-info.plist');
let obj = plist.parse(fs.readFileSync(infoPlistPath, 'utf8'));

let enableAppTracking = configParser.getPlatformPreference("EnableAppTrackingTransparencyPrompt", "ios");
if(enableAppTracking == "true" || enableAppTracking == ""){
var userTrackingDescription = configParser.getPlatformPreference("USER_TRACKING_DESCRIPTION_IOS", "ios");
let userTrackingDescription = configParser.getPlatformPreference("USER_TRACKING_DESCRIPTION_IOS", "ios");
if(userTrackingDescription != ""){
obj['NSUserTrackingUsageDescription'] = userTrackingDescription;
fs.writeFileSync(infoPlistPath, plist.build(obj));
}
}
else if(enableAppTracking == "false"){
delete obj['NSUserTrackingUsageDescription'];
fs.writeFileSync(infoPlistPath, plist.build(obj));
delete obj['NSUserTrackingUsageDescription'];
}
};

let collectionEnabled = configParser.getGlobalPreference("ANALYTICS_COLLECTION_ENABLED");
if (collectionEnabled.toLowerCase() == 'false') {
obj['FIREBASE_ANALYTICS_COLLECTION_ENABLED'] = false;
}

fs.writeFileSync(infoPlistPath, plist.build(obj));
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-firebase-analytics",
"version": "5.0.0-OS12",
"version": "5.0.0-OS13",
"description": "Cordova plugin for Firebase Analytics",
"cordova": {
"id": "cordova-plugin-firebase-analytics",
Expand Down
12 changes: 4 additions & 8 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-firebase-analytics"
version="5.0.0-OS12">
version="5.0.0-OS13">

<name>FirebaseAnalyticsPlugin</name>
<description>Cordova plugin for Firebase Analytics</description>
Expand All @@ -20,7 +20,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<engine name="cordova-ios" version=">=5.1.1"/>
</engines>

<preference name="ANALYTICS_COLLECTION_ENABLED" default="true" />
<preference name="AUTOMATIC_SCREEN_REPORTING_ENABLED" default="true" />
<preference name="USER_TRACKING_DESCRIPTION_IOS" default="$(PRODUCT_NAME) needs your attention." />

Expand All @@ -34,7 +33,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<config-file target="config.xml" parent="/*">
<feature name="FirebaseAnalytics">
<param name="ios-package" value="FirebaseAnalyticsPlugin" />
<param name="onload" value="$ANALYTICS_COLLECTION_ENABLED" />
<param name="onload" value="true" />
</feature>
</config-file>

Expand All @@ -44,9 +43,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
use a bit hacky method to set boolean value as a string:
https://developer.apple.com/documentation/foundation/nsstring/1409420-boolvalue?preferredLanguage=occ
-->
<config-file target="*-Info.plist" parent="FIREBASE_ANALYTICS_COLLECTION_ENABLED">
<string>$ANALYTICS_COLLECTION_ENABLED</string>
</config-file>
<config-file target="*-Info.plist" parent="FirebaseAutomaticScreenReportingEnabled">
<string>$AUTOMATIC_SCREEN_REPORTING_ENABLED</string>
</config-file>
Expand Down Expand Up @@ -88,11 +84,12 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<platform name="android">
<preference name="ANDROID_FIREBASE_ANALYTICS_VERSION" default="21.1.1"/>

<hook type="after_prepare" src="hooks/android/androidCopyPreferences.js" />

<config-file target="res/xml/config.xml" parent="/*">
<feature name="FirebaseAnalytics">
<param name="android-package" value="com.outsystems.plugins.firebase.analytics.FirebaseAnalyticsPlugin" />
<param name="onload" value="$ANALYTICS_COLLECTION_ENABLED" />
<param name="onload" value="true" />
</feature>
</config-file>

Expand All @@ -101,7 +98,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest/application">
<meta-data android:name="firebase_analytics_collection_enabled" android:value="$ANALYTICS_COLLECTION_ENABLED" />
<meta-data android:name="google_analytics_automatic_screen_reporting_enabled" android:value="$AUTOMATIC_SCREEN_REPORTING_ENABLED" />
</config-file>

Expand Down

0 comments on commit a35cc38

Please sign in to comment.