Skip to content

Commit

Permalink
Merge pull request #6 from audienceproject/feature/app-version
Browse files Browse the repository at this point in the history
Feature/app version
  • Loading branch information
ValeriiHAP authored Nov 16, 2021
2 parents e85034a + 7727a87 commit e8ca152
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 29 deletions.
11 changes: 10 additions & 1 deletion demo/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: "com.android.application"

import com.android.build.OutputFile
import groovy.json.JsonSlurper

/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
Expand Down Expand Up @@ -120,6 +121,14 @@ def jscFlavor = 'org.webkit:android-jsc:+'
*/
def enableHermes = project.ext.react.get("enableHermes", false);

def getAppVersion() {
def inputFile = new File("../../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}

def appVer = getAppVersion()

android {
ndkVersion rootProject.ext.ndkVersion

Expand All @@ -130,7 +139,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
versionName appVer
}
splits {
abi {
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@audienceproject/react-native-userreport-sdk",
"version": "3.0.4",
"version": "3.0.5",
"description": "Running UserReport in React Native applications",
"main": "react-native-userreport-sdk.js",
"repository": {
Expand All @@ -11,7 +11,8 @@
"license": "Apache-2.0",
"homepage": "https://github.com/audienceproject/userreport-react-native-sdk",
"scripts": {
"test": "jest"
"test": "jest",
"prepublishOnly": "npm install && npm run test"
},
"peerDependencies": {
"react-native": "^0.64.0",
Expand All @@ -21,8 +22,8 @@
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"babel-jest": "^27.1.0",
"eslint": "^7.14.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint": "^8.2.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.22.1",
"jest": "^27.1.0"
},
Expand Down
2 changes: 2 additions & 0 deletions react-native-userreport-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const fireTrackingPixel = async (trackingCode, consentString) => {
const idfa = await loadIdfa();
const idfv = ReactNativeDeviceInfo.getUniqueId();
const bundleId = ReactNativeDeviceInfo.getBundleId();
const appVersion = ReactNativeDeviceInfo.getVersion();

const systemName = ReactNativeDeviceInfo.getSystemName();
const systemVersion = ReactNativeDeviceInfo.getSystemVersion();
Expand All @@ -111,6 +112,7 @@ const fireTrackingPixel = async (trackingCode, consentString) => {
+ (!useAnonymousTracking && idfa ? `&d=${encodeURIComponent(idfa)}` : '')
+ (!useAnonymousTracking && idfv ? `&idfv=${encodeURIComponent(idfv)}` : '')
+ `&appid=${encodeURIComponent(bundleId)}`
+ `&appver=${encodeURIComponent(appVersion)}`
+ `&os=${encodeURIComponent(systemName)}`
+ `&osv=${encodeURIComponent(systemVersion)}`
+ `&dn=${encodeURIComponent(deviceName)}`
Expand Down
68 changes: 44 additions & 24 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jest.mock('react-native-device-info', () => ({

getBrand: () => '__DeviceInfoBrand__',
getDeviceId: () => '__DeviceInfoDeviceId__',
getVersion: () => '__VersionNumber__',
},
}), { virtual: true });

Expand Down Expand Up @@ -89,34 +90,42 @@ test('regular mode', async () => {

expect(fetch).toHaveBeenCalledTimes(3);

expect(fetch).toHaveBeenNthCalledWith(1,
'https://sak.userreport.com/publisherId/media/mediaId/ios.json');
expect(fetch).toHaveBeenNthCalledWith(
1,
'https://sak.userreport.com/publisherId/media/mediaId/ios.json',
);

expect(fetch).toHaveBeenNthCalledWith(2,
expect(fetch).toHaveBeenNthCalledWith(
2,
'https://visitanalytics.userreport.com/hit.gif'
+ '?t=__FetchMediaCode__'
+ '&r=4fzzzxjylrx'
+ '&rnd=4fzzzxjylrx'
+ '&d=__NativeAdvertisingId__'
+ '&idfv=__DeviceInfoUniqueId__'
+ '&med=__DeviceInfoBundleId__'
+ '&appid=__DeviceInfoBundleId__'
+ '&appver=__VersionNumber__'
+ '&os=__DeviceInfoSystemName__'
+ '&osv=__DeviceInfoSystemVersion__'
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
+ '&dr=150x300'
+ '&gdpr_consent=__FetchConsent__');
+ '&gdpr_consent=__FetchConsent__',
);

expect(fetch).toHaveBeenNthCalledWith(3,
expect(fetch).toHaveBeenNthCalledWith(
3,
'https://visitanalytics.userreport.com/hit.gif'
+ '?t=__FetchSectionCode__'
+ '&r=4fzzzxjylrx'
+ '&rnd=4fzzzxjylrx'
+ '&d=__NativeAdvertisingId__'
+ '&idfv=__DeviceInfoUniqueId__'
+ '&med=__DeviceInfoBundleId__'
+ '&appid=__DeviceInfoBundleId__'
+ '&appver=__VersionNumber__'
+ '&os=__DeviceInfoSystemName__'
+ '&osv=__DeviceInfoSystemVersion__'
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
+ '&dr=150x300'
+ '&gdpr_consent=__FetchConsent__');
+ '&gdpr_consent=__FetchConsent__',
);
});

test('legacy idfa', async () => {
Expand All @@ -127,18 +136,21 @@ test('legacy idfa', async () => {
UserReport.trackScreenView(),
]);

expect(fetch).toHaveBeenNthCalledWith(2,
expect(fetch).toHaveBeenNthCalledWith(
2,
'https://visitanalytics.userreport.com/hit.gif'
+ '?t=__FetchMediaCode__'
+ '&r=4fzzzxjylrx'
+ '&rnd=4fzzzxjylrx'
+ '&d=__NativeAdvertisingLegacyId__'
+ '&idfv=__DeviceInfoUniqueId__'
+ '&med=__DeviceInfoBundleId__'
+ '&appid=__DeviceInfoBundleId__'
+ '&appver=__VersionNumber__'
+ '&os=__DeviceInfoSystemName__'
+ '&osv=__DeviceInfoSystemVersion__'
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
+ '&dr=150x300'
+ '&gdpr_consent=__FetchConsent__');
+ '&gdpr_consent=__FetchConsent__',
);
});

test('dnt mode', async () => {
Expand All @@ -154,28 +166,36 @@ test('dnt mode', async () => {

expect(fetch).toHaveBeenCalledTimes(3);

expect(fetch).toHaveBeenNthCalledWith(1,
'https://sak.dnt-userreport.com/publisherId/media/mediaId/android.json');
expect(fetch).toHaveBeenNthCalledWith(
1,
'https://sak.dnt-userreport.com/publisherId/media/mediaId/android.json',
);

expect(fetch).toHaveBeenNthCalledWith(2,
expect(fetch).toHaveBeenNthCalledWith(
2,
'https://visitanalytics.dnt-userreport.com/hit.gif'
+ '?t=__FetchMediaCode__'
+ '&r=4fzzzxjylrx'
+ '&med=__DeviceInfoBundleId__'
+ '&rnd=4fzzzxjylrx'
+ '&appid=__DeviceInfoBundleId__'
+ '&appver=__VersionNumber__'
+ '&os=__DeviceInfoSystemName__'
+ '&osv=__DeviceInfoSystemVersion__'
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
+ '&dr=150x300'
+ '&gdpr_consent=__FetchConsent__');
+ '&gdpr_consent=__FetchConsent__',
);

expect(fetch).toHaveBeenNthCalledWith(3,
expect(fetch).toHaveBeenNthCalledWith(
3,
'https://visitanalytics.dnt-userreport.com/hit.gif'
+ '?t=__FetchSectionCode__'
+ '&r=4fzzzxjylrx'
+ '&med=__DeviceInfoBundleId__'
+ '&rnd=4fzzzxjylrx'
+ '&appid=__DeviceInfoBundleId__'
+ '&appver=__VersionNumber__'
+ '&os=__DeviceInfoSystemName__'
+ '&osv=__DeviceInfoSystemVersion__'
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
+ '&dr=150x300'
+ '&gdpr_consent=__FetchConsent__');
+ '&gdpr_consent=__FetchConsent__',
);
});

0 comments on commit e8ca152

Please sign in to comment.