.anonymizeIp(context.getResources().getBoolean(R.bool.ga_anonymizeIp)) .withHttpClient(new OkHttpClientImpl(gaConfig)) .build();
protected HttpClient createHttpClient() { if (httpClient != null) { return httpClient; } return new ApacheHttpClientImpl(config); }
public HttpRequest(String url) { this.setUrl(url); }
private void submitBatch(boolean force) { if (currentBatch.isEmpty()) { return; } if (isSubmitBatch(force)) { // Synchronized block is to ensure only one of the writers will actually write the batch. synchronized (currentBatch) { // If two threads pass the if condition and then one of them actually writes, // other will do the same since they were blocked sync block. this ensures that // others will not post it even if multiple threads were to wait at sync block at same time // https://en.wikipedia.org/wiki/Double-checked_locking if (isSubmitBatch(force)) { logger.debug("Submitting a batch of " + currentBatch.size() + " requests to GA"); httpClient.postBatch(new HttpBatchRequest().setUrl(config.getBatchUrl()).setRequests(currentBatch)); currentBatch.clear(); } } } }
@Override public HttpResponse post(HttpRequest req) { HttpResponse resp = new HttpResponse(); CloseableHttpResponse httpResp = null; try { httpResp = execute(req.getUrl(), new UrlEncodedFormEntity(createNameValuePairs(req), StandardCharsets.UTF_8)); resp.setStatusCode(httpResp.getStatusLine().getStatusCode()); } catch (Exception e) { if (e instanceof UnknownHostException) { logger.warn("Couldn't connect to Google Analytics. Internet may not be available. " + e.toString()); } else { logger.warn("Exception while sending the Google Analytics tracker request " + req, e); } } finally { EntityUtils.consumeQuietly(httpResp.getEntity()); try { httpResp.close(); } catch (Exception e2) { // ignore } } return resp; }
protected GoogleAnalyticsResponse postSingle(GoogleAnalyticsRequest<?> gaReq) { HttpRequest httpReq = createHttpRequest(gaReq); HttpResponse httpResp = httpClient.post(httpReq); GoogleAnalyticsResponse response = new GoogleAnalyticsResponse(); response.setStatusCode(httpResp.getStatusCode()); response.setRequestParams(httpReq.getBodyParams()); if (config.isGatherStats()) { gatherStats(gaReq); } return response; }
public HttpRequest post() { setMethod("POST"); return this; }
public ApacheHttpClientImpl(GoogleAnalyticsConfig config) { apacheHttpClient = createHttpClient(config); }
public BatchUrlEncodedFormEntity(List<List<NameValuePair>> parameters) { super(constructCombinedEntityString(parameters), ContentType.create(URLEncodedUtils.CONTENT_TYPE)); }
private HttpRequest createHttpRequest(GoogleAnalyticsRequest<?> gaReq) { HttpRequest httpReq = new HttpRequest(config.getUrl()); // Process the parameters processParameters(gaReq, httpReq); // Process custom dimensions processCustomDimensionParameters(gaReq, httpReq); // Process custom metrics processCustomMetricParameters(gaReq, httpReq); return httpReq; }
@Override public void close() { flush(); try { executor.shutdown(); } catch (Exception e) { // ignore } try { httpClient.close(); } catch (Exception e) { // ignore } }
private void submitBatch(boolean force) { if (currentBatch.isEmpty()) { return; } if (isSubmitBatch(force)) { // Synchronized block is to ensure only one of the writers will actually write the batch. synchronized (currentBatch) { // If two threads pass the if condition and then one of them actually writes, // other will do the same since they were blocked sync block. this ensures that // others will not post it even if multiple threads were to wait at sync block at same time // https://en.wikipedia.org/wiki/Double-checked_locking if (isSubmitBatch(force)) { logger.debug("Submitting a batch of " + currentBatch.size() + " requests to GA"); httpClient.postBatch(new HttpBatchRequest().setUrl(config.getBatchUrl()).setRequests(currentBatch)); currentBatch.clear(); } } } }
protected GoogleAnalyticsResponse postSingle(GoogleAnalyticsRequest<?> gaReq) { HttpRequest httpReq = createHttpRequest(gaReq); HttpResponse httpResp = httpClient.post(httpReq); GoogleAnalyticsResponse response = new GoogleAnalyticsResponse(); response.setStatusCode(httpResp.getStatusCode()); response.setRequestParams(httpReq.getBodyParams()); if (config.isGatherStats()) { gatherStats(gaReq); } return response; }
protected HttpClient createHttpClient() { if (httpClient != null) { return httpClient; } return new ApacheHttpClientImpl(config); }
public HttpRequest(String url) { this.setUrl(url); }
public HttpRequest post() { setMethod("POST"); return this; }
public ApacheHttpClientImpl(GoogleAnalyticsConfig config) { apacheHttpClient = createHttpClient(config); }
public BatchUrlEncodedFormEntity(List<List<NameValuePair>> parameters) { super(constructCombinedEntityString(parameters), ContentType.create(URLEncodedUtils.CONTENT_TYPE)); }
private HttpRequest createHttpRequest(GoogleAnalyticsRequest<?> gaReq) { HttpRequest httpReq = new HttpRequest(config.getUrl()); // Process the parameters processParameters(gaReq, httpReq); // Process custom dimensions processCustomDimensionParameters(gaReq, httpReq); // Process custom metrics processCustomMetricParameters(gaReq, httpReq); return httpReq; }
@Override public void close() { flush(); try { executor.shutdown(); } catch (Exception e) { // ignore } try { httpClient.close(); } catch (Exception e) { // ignore } }