Skip to content

Commit e8ca152

Browse files
Merge pull request #6 from audienceproject/feature/app-version
Feature/app version
2 parents e85034a + 7727a87 commit e8ca152

File tree

4 files changed

+61
-29
lines changed

4 files changed

+61
-29
lines changed

demo/android/app/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: "com.android.application"
22

33
import com.android.build.OutputFile
4+
import groovy.json.JsonSlurper
45

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

124+
def getAppVersion() {
125+
def inputFile = new File("../../package.json")
126+
def packageJson = new JsonSlurper().parseText(inputFile.text)
127+
return packageJson["version"]
128+
}
129+
130+
def appVer = getAppVersion()
131+
123132
android {
124133
ndkVersion rootProject.ext.ndkVersion
125134

@@ -130,7 +139,7 @@ android {
130139
minSdkVersion rootProject.ext.minSdkVersion
131140
targetSdkVersion rootProject.ext.targetSdkVersion
132141
versionCode 1
133-
versionName "1.0"
142+
versionName appVer
134143
}
135144
splits {
136145
abi {

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@audienceproject/react-native-userreport-sdk",
3-
"version": "3.0.4",
3+
"version": "3.0.5",
44
"description": "Running UserReport in React Native applications",
55
"main": "react-native-userreport-sdk.js",
66
"repository": {
@@ -11,7 +11,8 @@
1111
"license": "Apache-2.0",
1212
"homepage": "https://github.com/audienceproject/userreport-react-native-sdk",
1313
"scripts": {
14-
"test": "jest"
14+
"test": "jest",
15+
"prepublishOnly": "npm install && npm run test"
1516
},
1617
"peerDependencies": {
1718
"react-native": "^0.64.0",
@@ -21,8 +22,8 @@
2122
"@babel/core": "^7.15.0",
2223
"@babel/preset-env": "^7.15.0",
2324
"babel-jest": "^27.1.0",
24-
"eslint": "^7.14.0",
25-
"eslint-config-airbnb-base": "^14.2.1",
25+
"eslint": "^8.2.0",
26+
"eslint-config-airbnb-base": "^15.0.0",
2627
"eslint-plugin-import": "^2.22.1",
2728
"jest": "^27.1.0"
2829
},

react-native-userreport-sdk.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const fireTrackingPixel = async (trackingCode, consentString) => {
9595
const idfa = await loadIdfa();
9696
const idfv = ReactNativeDeviceInfo.getUniqueId();
9797
const bundleId = ReactNativeDeviceInfo.getBundleId();
98+
const appVersion = ReactNativeDeviceInfo.getVersion();
9899

99100
const systemName = ReactNativeDeviceInfo.getSystemName();
100101
const systemVersion = ReactNativeDeviceInfo.getSystemVersion();
@@ -111,6 +112,7 @@ const fireTrackingPixel = async (trackingCode, consentString) => {
111112
+ (!useAnonymousTracking && idfa ? `&d=${encodeURIComponent(idfa)}` : '')
112113
+ (!useAnonymousTracking && idfv ? `&idfv=${encodeURIComponent(idfv)}` : '')
113114
+ `&appid=${encodeURIComponent(bundleId)}`
115+
+ `&appver=${encodeURIComponent(appVersion)}`
114116
+ `&os=${encodeURIComponent(systemName)}`
115117
+ `&osv=${encodeURIComponent(systemVersion)}`
116118
+ `&dn=${encodeURIComponent(deviceName)}`

test.js

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jest.mock('react-native-device-info', () => ({
5050

5151
getBrand: () => '__DeviceInfoBrand__',
5252
getDeviceId: () => '__DeviceInfoDeviceId__',
53+
getVersion: () => '__VersionNumber__',
5354
},
5455
}), { virtual: true });
5556

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

9091
expect(fetch).toHaveBeenCalledTimes(3);
9192

92-
expect(fetch).toHaveBeenNthCalledWith(1,
93-
'https://sak.userreport.com/publisherId/media/mediaId/ios.json');
93+
expect(fetch).toHaveBeenNthCalledWith(
94+
1,
95+
'https://sak.userreport.com/publisherId/media/mediaId/ios.json',
96+
);
9497

95-
expect(fetch).toHaveBeenNthCalledWith(2,
98+
expect(fetch).toHaveBeenNthCalledWith(
99+
2,
96100
'https://visitanalytics.userreport.com/hit.gif'
97101
+ '?t=__FetchMediaCode__'
98-
+ '&r=4fzzzxjylrx'
102+
+ '&rnd=4fzzzxjylrx'
99103
+ '&d=__NativeAdvertisingId__'
100104
+ '&idfv=__DeviceInfoUniqueId__'
101-
+ '&med=__DeviceInfoBundleId__'
105+
+ '&appid=__DeviceInfoBundleId__'
106+
+ '&appver=__VersionNumber__'
102107
+ '&os=__DeviceInfoSystemName__'
103108
+ '&osv=__DeviceInfoSystemVersion__'
104109
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
105110
+ '&dr=150x300'
106-
+ '&gdpr_consent=__FetchConsent__');
111+
+ '&gdpr_consent=__FetchConsent__',
112+
);
107113

108-
expect(fetch).toHaveBeenNthCalledWith(3,
114+
expect(fetch).toHaveBeenNthCalledWith(
115+
3,
109116
'https://visitanalytics.userreport.com/hit.gif'
110117
+ '?t=__FetchSectionCode__'
111-
+ '&r=4fzzzxjylrx'
118+
+ '&rnd=4fzzzxjylrx'
112119
+ '&d=__NativeAdvertisingId__'
113120
+ '&idfv=__DeviceInfoUniqueId__'
114-
+ '&med=__DeviceInfoBundleId__'
121+
+ '&appid=__DeviceInfoBundleId__'
122+
+ '&appver=__VersionNumber__'
115123
+ '&os=__DeviceInfoSystemName__'
116124
+ '&osv=__DeviceInfoSystemVersion__'
117125
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
118126
+ '&dr=150x300'
119-
+ '&gdpr_consent=__FetchConsent__');
127+
+ '&gdpr_consent=__FetchConsent__',
128+
);
120129
});
121130

122131
test('legacy idfa', async () => {
@@ -127,18 +136,21 @@ test('legacy idfa', async () => {
127136
UserReport.trackScreenView(),
128137
]);
129138

130-
expect(fetch).toHaveBeenNthCalledWith(2,
139+
expect(fetch).toHaveBeenNthCalledWith(
140+
2,
131141
'https://visitanalytics.userreport.com/hit.gif'
132142
+ '?t=__FetchMediaCode__'
133-
+ '&r=4fzzzxjylrx'
143+
+ '&rnd=4fzzzxjylrx'
134144
+ '&d=__NativeAdvertisingLegacyId__'
135145
+ '&idfv=__DeviceInfoUniqueId__'
136-
+ '&med=__DeviceInfoBundleId__'
146+
+ '&appid=__DeviceInfoBundleId__'
147+
+ '&appver=__VersionNumber__'
137148
+ '&os=__DeviceInfoSystemName__'
138149
+ '&osv=__DeviceInfoSystemVersion__'
139150
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
140151
+ '&dr=150x300'
141-
+ '&gdpr_consent=__FetchConsent__');
152+
+ '&gdpr_consent=__FetchConsent__',
153+
);
142154
});
143155

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

155167
expect(fetch).toHaveBeenCalledTimes(3);
156168

157-
expect(fetch).toHaveBeenNthCalledWith(1,
158-
'https://sak.dnt-userreport.com/publisherId/media/mediaId/android.json');
169+
expect(fetch).toHaveBeenNthCalledWith(
170+
1,
171+
'https://sak.dnt-userreport.com/publisherId/media/mediaId/android.json',
172+
);
159173

160-
expect(fetch).toHaveBeenNthCalledWith(2,
174+
expect(fetch).toHaveBeenNthCalledWith(
175+
2,
161176
'https://visitanalytics.dnt-userreport.com/hit.gif'
162177
+ '?t=__FetchMediaCode__'
163-
+ '&r=4fzzzxjylrx'
164-
+ '&med=__DeviceInfoBundleId__'
178+
+ '&rnd=4fzzzxjylrx'
179+
+ '&appid=__DeviceInfoBundleId__'
180+
+ '&appver=__VersionNumber__'
165181
+ '&os=__DeviceInfoSystemName__'
166182
+ '&osv=__DeviceInfoSystemVersion__'
167183
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
168184
+ '&dr=150x300'
169-
+ '&gdpr_consent=__FetchConsent__');
185+
+ '&gdpr_consent=__FetchConsent__',
186+
);
170187

171-
expect(fetch).toHaveBeenNthCalledWith(3,
188+
expect(fetch).toHaveBeenNthCalledWith(
189+
3,
172190
'https://visitanalytics.dnt-userreport.com/hit.gif'
173191
+ '?t=__FetchSectionCode__'
174-
+ '&r=4fzzzxjylrx'
175-
+ '&med=__DeviceInfoBundleId__'
192+
+ '&rnd=4fzzzxjylrx'
193+
+ '&appid=__DeviceInfoBundleId__'
194+
+ '&appver=__VersionNumber__'
176195
+ '&os=__DeviceInfoSystemName__'
177196
+ '&osv=__DeviceInfoSystemVersion__'
178197
+ '&dn=__DeviceInfoBrand__%20__DeviceInfoDeviceId__'
179198
+ '&dr=150x300'
180-
+ '&gdpr_consent=__FetchConsent__');
199+
+ '&gdpr_consent=__FetchConsent__',
200+
);
181201
});

0 commit comments

Comments
 (0)