Back to project page GADemoGTM.
The source code is released under:
GNU General Public License
If you think the Android project GADemoGTM listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.pdro.gademogtm.gtm; //from w ww . j a v a 2s.c o m import android.content.Context; import com.google.android.gms.tagmanager.DataLayer; import com.google.android.gms.tagmanager.TagManager; /** * Utility class. */ // todo clean up the Utils class // todo ensure the documentation and implementation match what's in the dev doc guides public class Utils { private Utils() { // private constructor. } /** * Push an "openScreen" event with the given screen name. Tags that match that event will fire. */ public static void pushOpenScreenEvent(Context context, String screenName) { DataLayer dataLayer = TagManager.getInstance(context).getDataLayer(); dataLayer.pushEvent("screenVisible", DataLayer.mapOf("screenName", screenName)); } public static void pushEvent(Context context, String screenName, String category, String action, String label, String cd) { DataLayer dataLayer = TagManager.getInstance(context).getDataLayer(); dataLayer.pushEvent("gaEvent", DataLayer.mapOf("screenName", screenName, "category", category, "action", action, "label", label, "cdText",cd)); } public static void pushException(Context context, String screenName) { DataLayer dataLayer = TagManager.getInstance(context).getDataLayer(); dataLayer.pushEvent("exception", DataLayer.mapOf("screenName", screenName, "description", "Clicked the Exception Button")); } /** * Push a "closeScreen" event with the given screen name. Tags that match that event will fire. */ public static void pushCloseScreenEvent(Context context, String screenName) { DataLayer dataLayer = TagManager.getInstance(context).getDataLayer(); dataLayer.pushEvent("closeScreen", DataLayer.mapOf("screenName", screenName)); } public static void dispatchHits(Context context) { TagManager.getInstance(context).dispatch(); } }