-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Custom Dimensions plugin support;
Add dimensions id and variable limitations;
- Loading branch information
Showing
4 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
piwik-sdk/src/main/java/org/piwik/sdk/plugins/CustomDimensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.piwik.sdk.plugins; | ||
|
||
import org.piwik.sdk.Piwik; | ||
import org.piwik.sdk.tools.Logy; | ||
import org.piwik.sdk.TrackMe; | ||
|
||
/** | ||
* This plugins allows you to track any Custom Dimensions. | ||
* In order to use this functionality install and configure | ||
* https://plugins.piwik.org/CustomDimensions plugin. | ||
*/ | ||
public class CustomDimensions extends TrackMe { | ||
protected static final String LOGGER_TAG = Piwik.LOGGER_PREFIX + "CustomDimensions"; | ||
/** | ||
* This method sets a tracking API parameter dimension%dimensionId%=%dimensionValue%. | ||
* Eg dimension1=foo or dimension2=bar. | ||
* So the tracking API parameter starts with dimension followed by the set dimensionId. | ||
* @param dimensionId accepts values greater than 0 | ||
* @param dimensionValue is limited to 255 characters | ||
* @return instance of CustomDimensions plugin | ||
*/ | ||
public synchronized CustomDimensions set(int dimensionId, String dimensionValue) { | ||
if (dimensionId < 1){ | ||
Logy.w(LOGGER_TAG, "dimensionId should be great than 0"); | ||
return this; | ||
} | ||
if (dimensionValue != null && dimensionValue.length() > 255){ | ||
Logy.w(LOGGER_TAG, "dimensionValue will be truncated to 255 chars"); | ||
dimensionValue = dimensionValue.substring(0, 255); | ||
} | ||
set("dimension" + dimensionId, dimensionValue); | ||
return this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters