Skip to content

Commit

Permalink
feat: add autotrack switch (#213)
Browse files Browse the repository at this point in the history
* feat: add autotrack switch

* rename autotrack api

* feat: dynamic attrs (#215)

* feat: urlconnection response

* feat:add dynamic props generator

* feat:general props support all events

* remove custom event type.

* add database event validity period config in core config.

* feat:delete events for status 413

* substr json log if message is too large.

* update pre-release action ci.
  • Loading branch information
cpacm authored May 9, 2024
1 parent c09891d commit e2a0978
Show file tree
Hide file tree
Showing 54 changed files with 526 additions and 187 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/pre_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,27 @@ on:
jobs:
build:
if: ${{ github.event.label.name == 'pre release' }}
runs-on: macos-latest
runs-on: ubuntu-latest

steps:
- name: Delete unnecessary tools 🔧
uses: jlumbroso/[email protected]
with:
android: false # Don't remove Android tools
tool-cache: true # Remove image tool cache - rm -rf "$AGENT_TOOLSDIRECTORY"
dotnet: true # rm -rf /usr/share/dotnet
haskell: true # rm -rf /opt/ghc...
swap-storage: true # rm -f /mnt/swapfile (4GiB)
docker-images: false # Takes 16s, enable if needed in the future
large-packages: false # includes google-cloud-sdk and it's slow

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
ls /dev/kvm
- uses: actions/checkout@v3
with:
submodules: true
Expand Down Expand Up @@ -58,10 +76,11 @@ jobs:
with:
api-level: 31
target: default
disable-animations: true
ram-size: 4096M
cores: 4
arch: x86_64
disable-animations: true
disk-size: 6000M
heap-size: 600M
working-directory: ./demo
script: ./gradlew :app:connectedAndroidTest --stacktrace

Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ protobuf = "3.22.3"
powermock = "2.0.9"

# !!! SDK VERSION !!!
growingio = "4.2.0"
growingioCode = "40200"
growingioPlugin = "4.1.0"
growingio = "4.3.0"
growingioCode = "40300"
growingioPlugin = "4.2.0"

[plugins]
android-application = { id = "com.android.application", version.ref = "pluginGradle" }
Expand Down
9 changes: 7 additions & 2 deletions gradle/preRelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ test_plugin_version=$(grep "^growingioPlugin =.*" gradle/libs.versions.toml | aw
# echo $test_sdk_version
# echo $test_plugin_version

sed -i "" "s/^growingioPlugin =.*/${test_plugin_version}/g" demo/gradle/libs.versions.toml
sed -i "" "s/^growingio =.*/${test_sdk_version}/g" demo/gradle/libs.versions.toml
# for macOS
# sed -i "" "s/^growingioPlugin =.*/${test_plugin_version}/g" demo/gradle/libs.versions.toml
# sed -i "" "s/^growingio =.*/${test_sdk_version}/g" demo/gradle/libs.versions.toml

# for linux
sed -i "s/^growingioPlugin =.*/${test_plugin_version}/g" demo/gradle/libs.versions.toml
sed -i "s/^growingio =.*/${test_sdk_version}/g" demo/gradle/libs.versions.toml

# echo 'apply from: "${rootProject.projectDir.parent}/gradle/jacoco.gradle"' >> demo/app/build.gradle

Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ private void sendAbTestTrackEvent(ABExperiment abExperiment) {
.addAttribute("$exp_layer_id", abExperiment.getLayerId());
CustomEvent.Builder customEventBuilder = new CustomEvent.Builder();
customEventBuilder.setEventName("$exp_hit");
customEventBuilder.setCustomEventType(ConstantPool.CUSTOM_TYPE_SYSTEM);
customEventBuilder.setAttributes(attributesBuilder.build());
TrackMainThread.trackMain().cacheEventToTrackMain(customEventBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AutotrackConfig implements Configurable {
private boolean enableFragmentTag = false;
private final AutotrackOptions mAutotrackOptions = new AutotrackOptions();

private boolean autotrackEnabled = true;
private int pageXmlRes = 0;
private final List<PageRule> pageRules = new ArrayList<>();

Expand Down Expand Up @@ -144,4 +145,13 @@ public List<PageRule> getPageRules() {
public int getPageXmlRes() {
return pageXmlRes;
}

public boolean isAutotrack() {
return autotrackEnabled;
}

public AutotrackConfig setAutotrack(boolean enabled) {
this.autotrackEnabled = enabled;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void run() {

private final ViewTreeStatusObserver viewTreeStatusObserver;
private ActivityStateProvider activityStateProvider;
private AutotrackConfig autotrackConfig;

public ImpressionProvider() {
viewTreeStatusObserver = new ViewTreeStatusObserver(this);
Expand All @@ -68,10 +69,13 @@ public ImpressionProvider() {
@Override
public void setup(TrackerContext context) {

AutotrackConfig configuration = context.getConfigurationProvider().getConfiguration(AutotrackConfig.class);
impressionScale = configuration == null ? 0f : configuration.getImpressionScale();

autotrackConfig = context.getConfigurationProvider().getConfiguration(AutotrackConfig.class);
impressionScale = autotrackConfig == null ? 0f : autotrackConfig.getImpressionScale();
activityStateProvider = context.getActivityStateProvider();

if (autotrackConfig == null || !autotrackConfig.isAutotrack()) {
return;
}
activityStateProvider.registerActivityLifecycleListener(this);
}

Expand Down Expand Up @@ -165,6 +169,10 @@ public void trackViewImpression(View view, String impressionEventName, Map<Strin
if (view == null || TextUtils.isEmpty(impressionEventName)) {
return;
}
if (autotrackConfig == null || !autotrackConfig.isAutotrack()) {
Logger.d(TAG, "autotrack is not enabled");
return;
}
if (ViewAttributeUtil.isIgnoredView(view)) {
Logger.w(TAG, "Current view is set to ignore");
return;
Expand Down Expand Up @@ -215,6 +223,10 @@ public void stopTrackViewImpression(View trackedView) {
if (trackedView == null) {
return;
}
if (autotrackConfig == null || !autotrackConfig.isAutotrack()) {
Logger.d(TAG, "autotrack is not enabled");
return;
}
Activity activity = findViewActivity(trackedView);
if (activity == null) {
Logger.e(TAG, "TrackedView context activity is NULL");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ public class ViewChangeProvider implements IActivityLifecycle, OnViewStateChange

@Override
public void setup(TrackerContext context) {
activityStateProvider = context.getActivityStateProvider();
autotrackConfig = context.getConfigurationProvider().getConfiguration(AutotrackConfig.class);
activityStateProvider.registerActivityLifecycleListener(this);
activityStateProvider = context.getActivityStateProvider();
viewNodeProvider = context.getProvider(ViewNodeProvider.class);

if (autotrackConfig == null || !autotrackConfig.isAutotrack()) return;
activityStateProvider.registerActivityLifecycleListener(this);
viewTreeStatusObserver = new ViewTreeStatusObserver(false, false, true, false, this,
R.id.growing_tracker_monitoring_focus_change);
}
Expand All @@ -67,7 +68,7 @@ public void shutdown() {
@Override
public void onActivityLifecycle(ActivityLifecycleEvent event) {
Activity activity = event.getActivity();
if (activity == null) {
if (activity == null || viewTreeStatusObserver == null) {
return;
}
if (event.eventType == ActivityLifecycleEvent.EVENT_TYPE.ON_RESUMED) {
Expand Down Expand Up @@ -138,6 +139,11 @@ private void sendChangeEvent(View view) {
Logger.e(TAG, "Autotracker do not initialized successfully");
}

if (autotrackConfig == null || !autotrackConfig.isAutotrack()) {
Logger.d(TAG, "autotrack is not enabled");
return;
}

if (view == null) {
Logger.e(TAG, "viewOnChange:View is NULL");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ public void viewOnClick(View view) {
return;
}

if (autotrackConfig == null || !autotrackConfig.isAutotrack()) {
Logger.d(TAG, "autotrack is not enabled");
return;
}

if (view == null) {
Logger.e(TAG, "viewOnClick: view is NULL");
return;
Expand All @@ -207,6 +212,11 @@ public void menuItemOnClick(Activity activity, MenuItem menuItem) {
return;
}

if (autotrackConfig == null || !autotrackConfig.isAutotrack()) {
Logger.d(TAG, "autotrack is not enabled");
return;
}

if (activity == null || menuItem == null) {
Logger.e(TAG, "menuItemOnClick: activity or menuItem is NULL");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ public String getClassName() {

@Override
public boolean isAutotrack() {
if (pageConfig == null || !pageConfig.isAutotrack()) {
return false;
}
// cdp downgrade when activity page is enabled
if (pageConfig != null && pageConfig.isActivityPageEnabled()) {
if (pageConfig.isActivityPageEnabled()) {
return !isIgnored();
}
return super.isAutotrack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ private String transformSwitcherTag(String tag) {

@Override
public boolean isAutotrack() {
if (pageConfig == null || !pageConfig.isAutotrack()) {
return false;
}
// cdp downgrade when fragment page is enabled
if (pageConfig != null && pageConfig.isFragmentPageEnabled()) {
if (pageConfig.isFragmentPageEnabled()) {
return !isIgnored();
}
return super.isAutotrack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.growingio.android.sdk.track.utils.ClassExistHelper;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -90,7 +90,10 @@ public Map<String, String> getAttributes() {
}

public void setAttributes(Map<String, String> attributes) {
mAttributes = attributes;
if (mAttributes == null) mAttributes = new HashMap<>();
mAttributes.clear();
if (attributes == null) return;
mAttributes.putAll(attributes);
}

public abstract String getName();
Expand Down Expand Up @@ -188,7 +191,7 @@ public String activePath() {
public Map<String, String> activeAttributes() {
Page<?> activePage = lastActivePage();
if (activePage != null) return activePage.getAttributes();
return Collections.emptyMap();
return null;
}

public String getXIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ class PageConfig {
private boolean isFragmentPageEnabled = true;
private boolean isDowngrade = false;

public PageConfig(List<PageRule> pageRuleList, boolean isActivityPageEnabled, boolean isFragmentPageEnabled, boolean enableFragmentTag, boolean isDowngrade) {
private boolean autotrack = true;

public PageConfig(List<PageRule> pageRuleList, boolean isActivityPageEnabled, boolean isFragmentPageEnabled, boolean enableFragmentTag, boolean isDowngrade,boolean autotrack) {
this.pageRuleList = pageRuleList;
this.isActivityPageEnabled = isActivityPageEnabled;
this.isFragmentPageEnabled = isFragmentPageEnabled;
this.enableFragmentTag = enableFragmentTag;
this.isDowngrade = isDowngrade;
this.autotrack = autotrack;
}

public boolean isEnableFragmentTag() {
Expand All @@ -52,4 +55,8 @@ public boolean isFragmentPageEnabled() {
public boolean isDowngrade() {
return isDowngrade;
}

public boolean isAutotrack() {
return autotrack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@


import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -72,14 +71,16 @@ private PageProvider() {
@Override
public void setup(TrackerContext context) {
activityStateProvider = context.getActivityStateProvider();
activityStateProvider.registerActivityLifecycleListener(this);
loadPageConfig(context);
}

private void loadPageConfig(TrackerContext context) {
ConfigurationProvider configurationProvider = context.getConfigurationProvider();
AutotrackConfig autotrackConfig = configurationProvider.getConfiguration(AutotrackConfig.class);
boolean isDowngrade = configurationProvider.isDowngrade();

loadPageConfig(context, autotrackConfig, configurationProvider.isDowngrade());

activityStateProvider.registerActivityLifecycleListener(this);
}

private void loadPageConfig(TrackerContext context, AutotrackConfig autotrackConfig, boolean isDowngrade) {
if (autotrackConfig != null) {
boolean isActivityPageEnabled = autotrackConfig.getAutotrackOptions().isActivityPageEnabled();
boolean isFragmentPageEnabled = autotrackConfig.getAutotrackOptions().isFragmentPageEnabled();
Expand All @@ -88,15 +89,17 @@ private void loadPageConfig(TrackerContext context) {
autotrackConfig.getPageRules().addAll(0, pageRuleList);

List<PageRule> pageRules = Collections.unmodifiableList(autotrackConfig.getPageRules());
pageConfig = new PageConfig(pageRules, isActivityPageEnabled, isFragmentPageEnabled, enableFragmentTag, isDowngrade);
pageConfig = new PageConfig(pageRules, isActivityPageEnabled, isFragmentPageEnabled, enableFragmentTag, isDowngrade, autotrackConfig.isAutotrack());
} else {
pageConfig = new PageConfig(null, isDowngrade, isDowngrade, false, isDowngrade);
pageConfig = new PageConfig(null, isDowngrade, isDowngrade, false, isDowngrade, true);
}
}


@Override
public void shutdown() {
ALL_PAGE_TREE.clear();
CACHE_PAGES.clear();
activityStateProvider.unregisterActivityLifecycleListener(this);
}

Expand Down Expand Up @@ -513,8 +516,7 @@ public void setPageAttributes(SuperFragment<?> fragment, Map<String, String> att
}

private void setPageAttributes(Page<?> page, Map<String, String> attributes) {
if (page == null) return;
if (attributes == null) attributes = new HashMap<>();
if (page == null || attributes == null) return;
if (attributes.equals(page.getAttributes())) {
Logger.w(TAG, "setPageAttributes is equals page.getAttributes");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.android.material.tabs.TabLayout;
import com.growingio.android.sdk.autotrack.shadow.ListMenuItemViewShadow;
import com.growingio.android.sdk.track.TrackMainThread;
import com.growingio.android.sdk.track.log.Logger;
import com.growingio.android.sdk.track.utils.ClassExistHelper;

public class ViewUtil {
Expand Down Expand Up @@ -107,8 +108,13 @@ public static String getWidgetContent(View widget) {
return compoundButtonContentValue((CompoundButton) widget);
}
if (ClassExistHelper.hasClass("com.google.android.material.tabs.TabLayout")) {
if (widget instanceof TabLayout.TabView) {
return tabViewContentValue((TabLayout.TabView) widget);
try {
if (widget instanceof TabLayout.TabView) {
return tabViewContentValue((TabLayout.TabView) widget);
}
} catch (IllegalAccessError e) {
// TabLayout.TabView在1.1.0版本才开始修改为public访问权限
Logger.e("ViewUtil", "TabLayout version is low.");
}
}
if (ClassExistHelper.hasClass("com.google.android.material.slider.Slider")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public EventDbResult executeData() {
}
}


private EventDbResult executeDatabase(EventDatabase database) throws IllegalArgumentException {
EventDbResult dbResult = new EventDbResult();
if (database.getDbOp() == EventDatabase.DATABASE_OP_INSERT) {
Expand All @@ -61,7 +60,8 @@ private EventDbResult executeDatabase(EventDatabase database) throws IllegalArgu
dbResult.setSuccess(count == database.getEvents().size());
return dbResult;
} else if (database.getDbOp() == EventDatabase.DATABASE_OP_OUTDATED) {
int sum = dataManager.removeOverdueEvents();
int day = database.getLimit();
int sum = dataManager.removeOverdueEvents(day);
dbResult.setSum(sum);
dbResult.setSuccess(sum >= 0);
return dbResult;
Expand Down
Loading

0 comments on commit e2a0978

Please sign in to comment.