Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from yandexmobile/release-0.2.0
Browse files Browse the repository at this point in the history
Release AppMetrica Cordova Plugin 0.2.0
  • Loading branch information
NesterovichAlexey authored Dec 26, 2017
2 parents 6db526a + 27118a3 commit 4c0e850
Show file tree
Hide file tree
Showing 21 changed files with 256 additions and 162 deletions.
89 changes: 56 additions & 33 deletions LICENSE.md

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# AppMetrica Cordova Plugin

## Documentation
Common documentation available on [metrica official site][DOCUMENTATION].
Common documentation available on [AppMetrica official site][DOCUMENTATION].
Documentation for this plugin will be published soon.

## Sample project
Expand All @@ -27,6 +27,11 @@ advertisement**.

## Changelog

### Version 0.2.0
* Updated versions of the AppMetrica SDK (iOS 2.9.4 and Android 2.78)
* Added a method for getting the configuration of the AppMetrica Push Cordova plugin.
* Fixed installation of iOS part from NPM (#1).

### Version 0.1.0
* Implemented plugin for AppMetrica iOS (v2.8.0) and AppMetrica Android (v2.62).
* Provided sample.
Expand All @@ -35,6 +40,6 @@ advertisement**.
License agreement on use of Yandex AppMetrica is available at [EULA site][LICENSE]


[LICENSE]: https://yandex.com/legal/metrica_termsofuse/ "Yandex AppMetrica agreement"
[LICENSE]: https://yandex.com/legal/appmetrica_sdk_agreement/ "Yandex AppMetrica agreement"
[DOCUMENTATION]: https://tech.yandex.com/appmetrica/doc/mobile-sdk-dg/concepts/about-docpage/ "Yandex AppMetrica documentation"
[GitHubSAMPLE]: https://github.com/yandexmobile/metrica-plugin-cordova/tree/master/sample "Sample from reository"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yandex-appmetrica-plugin-cordova",
"version": "0.1.0",
"version": "0.2.0",
"description": "Cordova/PhoneGap plugin for AppMetrica analytics tool",
"cordova": {
"id": "yandex-appmetrica-plugin-cordova",
Expand Down
11 changes: 11 additions & 0 deletions platforms/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repositories{
jcenter()
mavenCentral()
flatDir {
dirs 'libs'
}
}

dependencies {
compile(name:'mobmetricalib-2.78', ext:'aar')
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
* AppMetricaPlugin.java
*
* This file is a part of the AppMetrica.
*
* Version for Android © 2017 YANDEX
*
* Version for Cordova/PhoneGap
* © 2017 YANDEX
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://yandex.com/legal/metrica_termsofuse/
* You may obtain a copy of the License at
* https://yandex.com/legal/appmetrica_sdk_agreement/
*/

package com.yandex.metrica.plugin.cordova;
Expand Down Expand Up @@ -78,17 +75,17 @@ public void run() {
}

@Override
public void onPause(boolean multitasking) {
public void onPause(final boolean multitasking) {
onPauseActivity();
}

@Override
public void onResume(boolean multitasking) {
public void onResume(final boolean multitasking) {
onResumeActivity();
}

@Override
public void onNewIntent(Intent intent) {
public void onNewIntent(final Intent intent) {
getAppMetricaExecutor().execute(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -125,8 +122,8 @@ private void onResumeActivity() {
}
}

private Location toLocation(JSONObject locationObj) throws JSONException {
Location location = new Location("Custom");
public static Location toLocation(final JSONObject locationObj) throws JSONException {
final Location location = new Location("Custom");

if (locationObj.has("latitude")) {
location.setLatitude(locationObj.getDouble("latitude"));
Expand All @@ -153,9 +150,9 @@ private Location toLocation(JSONObject locationObj) throws JSONException {
return location;
}

private YandexMetricaConfig toConfig(JSONObject configObj) throws JSONException {
String apiKey = configObj.getString("apiKey");
YandexMetricaConfig.Builder builder = YandexMetricaConfig.newConfigBuilder(apiKey);
public static YandexMetricaConfig toConfig(final JSONObject configObj) throws JSONException {
final String apiKey = configObj.getString("apiKey");
final YandexMetricaConfig.Builder builder = YandexMetricaConfig.newConfigBuilder(apiKey);

if (configObj.has("handleFirstActivationAsUpdateEnabled")) {
builder.handleFirstActivationAsUpdate(configObj.getBoolean("handleFirstActivationAsUpdateEnabled"));
Expand All @@ -176,17 +173,17 @@ private YandexMetricaConfig toConfig(JSONObject configObj) throws JSONException
builder.setLogEnabled();
}
if (configObj.has("location")) {
Location location = toLocation(configObj.getJSONObject("location"));
final Location location = toLocation(configObj.getJSONObject("location"));
builder.setLocation(location);
}
if (configObj.has("preloadInfo")) {
JSONObject preloadInfoObj = configObj.getJSONObject("preloadInfo");
PreloadInfo.Builder infoBuilder = PreloadInfo.newBuilder(preloadInfoObj.getString("trackingId"));
JSONObject additionalInfoObj = preloadInfoObj.optJSONObject("additionalInfo");
final JSONObject preloadInfoObj = configObj.getJSONObject("preloadInfo");
final PreloadInfo.Builder infoBuilder = PreloadInfo.newBuilder(preloadInfoObj.getString("trackingId"));
final JSONObject additionalInfoObj = preloadInfoObj.optJSONObject("additionalInfo");
if (additionalInfoObj != null) {
for (Iterator<String> keyIterator = additionalInfoObj.keys(); keyIterator.hasNext();) {
String key = keyIterator.next();
String value = additionalInfoObj.getString(key);
final String key = keyIterator.next();
final String value = additionalInfoObj.getString(key);
infoBuilder.setAdditionalParams(key, value);
}
}
Expand All @@ -196,29 +193,31 @@ private YandexMetricaConfig toConfig(JSONObject configObj) throws JSONException
return builder.build();
}

private void activate(JSONArray args, final CallbackContext callbackContext) throws JSONException {
private void activate(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final JSONObject configObj = args.getJSONObject(0);
final YandexMetricaConfig config = toConfig(configObj);

Context context = getActivity().getApplicationContext();
final Context context = getActivity().getApplicationContext();
YandexMetrica.activate(context, config);

synchronized (mLock) {
if (mAppMetricaActivated == false) {
YandexMetrica.reportAppOpen(getActivity());
if (mActivityPaused == false) {
onResumeActivity();
YandexMetrica.onResumeActivity(getActivity());
}
}
mAppMetricaActivated = true;
}
}

private void reportEvent(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void reportEvent(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final String eventName = args.getString(0);
String eventParametersJSONString = null;
try {
JSONObject eventParametersObj = args.getJSONObject(1);
final JSONObject eventParametersObj = args.getJSONObject(1);
eventParametersJSONString = eventParametersObj.toString();
} catch (JSONException ignored) {}

Expand All @@ -229,60 +228,69 @@ private void reportEvent(JSONArray args, CallbackContext callbackContext) throws
}
}

private void reportError(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void reportError(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final String errorName = args.getString(0);
Throwable errorThrowable = null;
try {
String errorReason = args.getString(1);
final String errorReason = args.getString(1);
errorThrowable = new Throwable(errorReason);
} catch (JSONException ignored) {}

YandexMetrica.reportError(errorName, errorThrowable);
}

private void setCustomAppVersion(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void setCustomAppVersion(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final String appVersion = args.getString(0);

YandexMetrica.setCustomAppVersion(appVersion);
}

private void setLocation(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void setLocation(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final JSONObject locationObj = args.getJSONObject(0);

Location location = toLocation(locationObj);
final Location location = toLocation(locationObj);
YandexMetrica.setLocation(location);
}

private void setTrackLocationEnabled(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void setTrackLocationEnabled(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final boolean enabled = args.getBoolean(0);

YandexMetrica.setTrackLocationEnabled(enabled);
}

private void setEnvironmentValue(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void setEnvironmentValue(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final String key = args.getString(0);
final String value = args.getString(1);

YandexMetrica.setEnvironmentValue(key, value);
}

private void setSessionTimeout(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void setSessionTimeout(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final int sessionTimeout = args.getInt(0);

YandexMetrica.setSessionTimeout(sessionTimeout);
}

private void setReportCrashesEnabled(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void setReportCrashesEnabled(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final boolean enabled = args.getBoolean(0);

YandexMetrica.setReportCrashesEnabled(enabled);
}

private void setLoggingEnabled(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void setLoggingEnabled(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
YandexMetrica.setLogEnabled();
}

private void setCollectInstalledAppsEnabled(JSONArray args, CallbackContext callbackContext) throws JSONException {
private void setCollectInstalledAppsEnabled(final JSONArray args,
final CallbackContext callbackContext) throws JSONException {
final boolean enabled = args.getBoolean(0);

YandexMetrica.setCollectInstalledApps(enabled);
Expand Down
Binary file removed platforms/android/mobmetricalib-2.62.jar
Binary file not shown.
Binary file added platforms/android/mobmetricalib-2.78.aar
Binary file not shown.
13 changes: 6 additions & 7 deletions platforms/ios/YMMAppMetricaPlugin.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
* YMMAppMetricaPlugin.h
*
* This file is a part of the AppMetrica.
*
* Version for iOS © 2017 YANDEX
*
* Version for Cordova/PhoneGap
* © 2017 YANDEX
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://yandex.com/legal/metrica_termsofuse/
* You may obtain a copy of the License at
* https://yandex.com/legal/appmetrica_sdk_agreement/
*/

#import <Cordova/CDVPlugin.h>
Expand All @@ -24,5 +21,7 @@
- (void)setReportCrashesEnabled:(CDVInvokedUrlCommand *)command;
- (void)setLoggingEnabled:(CDVInvokedUrlCommand *)command;
- (void)setCollectInstalledAppsEnabled:(CDVInvokedUrlCommand *)command;
+ (void)activateWithConfigurationDictionary:(NSDictionary *)configuration;
+ (bool)isAppMetricaActivated;

@end
34 changes: 22 additions & 12 deletions platforms/ios/YMMAppMetricaPlugin.m
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/*
* YMMAppMetricaPlugin.m
*
* This file is a part of the AppMetrica.
*
* Version for iOS © 2017 YANDEX
*
* Version for Cordova/PhoneGap
* © 2017 YANDEX
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://yandex.com/legal/metrica_termsofuse/
* You may obtain a copy of the License at
* https://yandex.com/legal/appmetrica_sdk_agreement/
*/

#import "YMMAppMetricaPlugin.h"

#import <YandexMobileMetrica/YandexMobileMetrica.h>
#import <CoreLocation/CoreLocation.h>

static bool gYMMIsAppMetricaActivated = false;

@implementation YMMAppMetricaPlugin

- (void)handleOpenURL:(NSNotification *)notification
Expand All @@ -35,8 +34,7 @@ - (void)activate:(CDVInvokedUrlCommand *)command
NSDictionary *configurationDictionary = [command argumentAtIndex:0 withDefault:nil andClass:[NSDictionary class]];

[self dispatchAsync:^{
YMMYandexMetricaConfiguration *configuration = [self configurationForDictionary:configurationDictionary];
[YMMYandexMetrica activateWithConfiguration:configuration];
[[self class] activateWithConfigurationDictionary:configurationDictionary];
}];
}

Expand Down Expand Up @@ -79,7 +77,7 @@ - (void)setLocation:(CDVInvokedUrlCommand *)command
NSDictionary *locationDictionary = [command argumentAtIndex:0 withDefault:nil andClass:[NSDictionary class]];

[self dispatchAsync:^{
CLLocation *location = [self locationForDictionary:locationDictionary];
CLLocation *location = [[self class] locationForDictionary:locationDictionary];
[YMMYandexMetrica setLocation:location];
}];
}
Expand Down Expand Up @@ -150,7 +148,7 @@ - (void)setCollectInstalledAppsEnabled:(CDVInvokedUrlCommand *)command
};
}

- (YMMYandexMetricaConfiguration *)configurationForDictionary:(NSDictionary *)configurationDictionary
+ (YMMYandexMetricaConfiguration *)configurationForDictionary:(NSDictionary *)configurationDictionary
{
NSString *apiKey = configurationDictionary[@"apiKey"];
YMMYandexMetricaConfiguration *configuration = [[YMMYandexMetricaConfiguration alloc] initWithApiKey:apiKey];
Expand Down Expand Up @@ -199,7 +197,7 @@ - (YMMYandexMetricaConfiguration *)configurationForDictionary:(NSDictionary *)co
return configuration;
}

- (CLLocation *)locationForDictionary:(NSDictionary *)locationDictionary
+ (CLLocation *)locationForDictionary:(NSDictionary *)locationDictionary
{
if (locationDictionary == nil) {
return nil;
Expand Down Expand Up @@ -231,4 +229,16 @@ - (void)dispatchAsync:(dispatch_block_t)block
[self.commandDelegate runInBackground:block];
}

+ (void)activateWithConfigurationDictionary:(NSDictionary *)configuration
{
YMMYandexMetricaConfiguration *config = [[self class] configurationForDictionary:configuration];
[YMMYandexMetrica activateWithConfiguration:config];
gYMMIsAppMetricaActivated = true;
}

+ (bool)isAppMetricaActivated
{
return gYMMIsAppMetricaActivated;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* This file is a part of the AppMetrica
*
* Version for iOS © 2016 YANDEX
* Version for iOS © 2017 YANDEX
*
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://legal.yandex.com/metrica_termsofuse/
Expand All @@ -13,9 +13,9 @@
#define __YMM_VERSION_H__

#define YMM_VERSION_MAJOR 2
#define YMM_VERSION_MINOR 8
#define YMM_VERSION_PATCH 0
#define YMM_VERSION_MINOR 9
#define YMM_VERSION_PATCH 4

#define YMM_BUILD_NUMBER 7224
#define YMM_BUILD_NUMBER 8876

#endif // __YMM_VERSION_H__
Loading

0 comments on commit 4c0e850

Please sign in to comment.