コード例 #1
0
 /**
  * Get parameters
  *
  * @param hit String
  * @return HashMap
  */
 static LinkedHashMap<String, String> getParameters(String hit) {
   LinkedHashMap<String, String> map = new LinkedHashMap<>();
   try {
     URL url = new URL(hit);
     map.put("ssl", url.getProtocol().equals("http") ? "Off" : "On");
     map.put("log", url.getHost());
     String[] queryComponents = url.getQuery().split("&");
     for (String queryComponent : queryComponents) {
       String[] elem = queryComponent.split("=");
       if (elem.length > 1) {
         elem[1] = Tool.percentDecode(elem[1]);
         if (Tool.parseJSON(elem[1]) instanceof JSONObject) {
           JSONObject json = (JSONObject) Tool.parseJSON(elem[1]);
           if (json != null && elem[0].equals(Hit.HitParam.JSON.stringValue())) {
             map.put(elem[0], json.toString(3));
           } else {
             map.put(elem[0], elem[1]);
           }
         } else {
           map.put(elem[0], elem[1]);
         }
       } else {
         map.put(elem[0], "");
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return map;
 }
コード例 #2
0
 /**
  * Return a appended String
  *
  * @param key String
  * @param volatileParams ArrayList<Param>
  * @param persistentParams ArrayList<Param>
  * @return String
  */
 static String appendParameterValues(
     String key, ArrayList<Param> volatileParams, ArrayList<Param> persistentParams) {
   ArrayList<int[]> indexPositions =
       Tool.findParameterPosition(key, volatileParams, persistentParams);
   boolean isFirst = true;
   String result = "";
   for (int[] index : indexPositions) {
     Param param = index[0] == 0 ? volatileParams.get(index[1]) : persistentParams.get(index[1]);
     if (isFirst) {
       result = param.getValue().execute();
       isFirst = false;
     } else if (param.getOptions() != null) {
       result += param.getOptions().getSeparator() + param.getValue().execute();
     } else {
       result += "," + param.getValue().execute();
     }
   }
   return result;
 }
コード例 #3
0
  public void dispatch(BusinessObject... businessObjects) {
    ArrayList<BusinessObject> trackerObjects;
    for (BusinessObject businessObject : businessObjects) {
      businessObject.setEvent();

      if (businessObject instanceof AbstractScreen) {
        trackerObjects =
            new ArrayList<BusinessObject>() {
              {
                addAll(tracker.getBusinessObjects().values());
              }
            };

        boolean hasOrder = false;

        for (BusinessObject object : trackerObjects) {
          if (((object instanceof OnAppAd && ((OnAppAd) object).getAction() == OnAppAd.Action.View)
                  || object instanceof Order
                  || object instanceof InternalSearch
                  || object instanceof ScreenInfo)
              && object.getTimestamp() < businessObject.getTimestamp()) {

            if (object instanceof Order) {
              hasOrder = true;
            }

            object.setEvent();
            tracker.getBusinessObjects().remove(object.getId());
          }
        }

        if (tracker.Cart().getCartId() != null
            && (((Screen) businessObject).isBasketScreen() || hasOrder)) {
          tracker.Cart().setEvent();
        }
      } else if (businessObject instanceof Gesture) {
        trackerObjects =
            new ArrayList<BusinessObject>() {
              {
                addAll(tracker.getBusinessObjects().values());
              }
            };

        if (((Gesture) businessObject).getAction() == Gesture.Action.InternalSearch) {
          for (BusinessObject object : trackerObjects) {
            if ((object instanceof InternalSearch)
                && object.getTimestamp() < businessObject.getTimestamp()) {
              object.setEvent();
              tracker.getBusinessObjects().remove(object.getId());
            }
          }
        }
      }

      tracker.getBusinessObjects().remove(businessObject.getId());
      trackerObjects =
          new ArrayList<BusinessObject>() {
            {
              addAll(tracker.getBusinessObjects().values());
            }
          };

      for (BusinessObject object : trackerObjects) {
        if ((object instanceof CustomObject || object instanceof NuggAd)
            && object.getTimestamp() < businessObject.getTimestamp()) {
          object.setEvent();
          tracker.getBusinessObjects().remove(object.getId());
        }
      }
    }

    if (Hit.getHitType(
            tracker.getBuffer().getVolatileParams(), tracker.getBuffer().getPersistentParams())
        == Hit.HitType.Screen) {
      TechnicalContext.screenName =
          Tool.appendParameterValues(
              Hit.HitParam.Screen.stringValue(),
              tracker.getBuffer().getVolatileParams(),
              tracker.getBuffer().getPersistentParams());
      CrashDetectionHandler.setCrashLastScreen(TechnicalContext.screenName);

      String level2 =
          Tool.appendParameterValues(
              Hit.HitParam.Level2.stringValue(),
              tracker.getBuffer().getVolatileParams(),
              tracker.getBuffer().getPersistentParams());
      TechnicalContext.level2 = (!TextUtils.isEmpty(level2)) ? Integer.parseInt(level2) : 0;

      SharedPreferences preferences = Tracker.getPreferences();
      if (!preferences.getBoolean(TrackerConfigurationKeys.CAMPAIGN_ADDED_KEY, false)) {
        String xtor =
            preferences.getString(TrackerConfigurationKeys.MARKETING_CAMPAIGN_SAVED, null);
        if (xtor != null) {
          ParamOption beforeStcPositionWithEncoding =
              new ParamOption()
                  .setRelativePosition(ParamOption.RelativePosition.before)
                  .setRelativeParameterKey(Hit.HitParam.JSON.stringValue())
                  .setEncode(true);

          if (preferences.getBoolean(
              TrackerConfigurationKeys.IS_FIRST_AFTER_INSTALL_HIT_KEY, true)) {
            tracker.setParam(
                Hit.HitParam.Source.stringValue(), xtor, beforeStcPositionWithEncoding);
            preferences
                .edit()
                .putBoolean(TrackerConfigurationKeys.IS_FIRST_AFTER_INSTALL_HIT_KEY, false)
                .apply();
          } else {
            tracker.setParam(
                Hit.HitParam.RemanentSource.stringValue(), xtor, beforeStcPositionWithEncoding);
          }
          preferences.edit().putBoolean(TrackerConfigurationKeys.CAMPAIGN_ADDED_KEY, true).apply();
        }
      }
    }

    setIdentifiedVisitorInfos();

    ParamOption appendWithEncoding = new ParamOption().setAppend(true).setEncode(true);
    tracker.setParam(
        Hit.HitParam.JSON.stringValue(),
        LifeCycle.getMetrics(Tracker.getPreferences()),
        appendWithEncoding);
    if ((Boolean) tracker.getConfiguration().get(TrackerConfigurationKeys.ENABLE_CRASH_DETECTION)) {
      tracker.setParam(
          Hit.HitParam.JSON.stringValue(),
          CrashDetectionHandler.getCrashInformation(),
          appendWithEncoding);
    }

    String referrer = Tracker.getPreferences().getString(TrackerConfigurationKeys.REFERRER, null);
    if (!TextUtils.isEmpty(referrer)) {
      tracker.setParam(Hit.HitParam.Refstore.stringValue(), referrer);
      Tracker.getPreferences().edit().putString(TrackerConfigurationKeys.REFERRER, null).apply();
    }

    Builder builder = new Builder(tracker);
    tracker.getBuffer().getVolatileParams().clear();
    TrackerQueue.getInstance().put(builder);

    tracker.Context().setLevel2(tracker.Context().getLevel2());
  }