Tuesday, 15 July 2014

Android development using Google Tag Manager and dataLayer -



Android development using Google Tag Manager and dataLayer -

i'm new google tag manager stuff , kinda got ears tangled trying test it. here's i've done:

created gtm account; created container; created custom image tag; added rule custom image tag;

now here's code:

package com.google.android.tagmanager.examples.helloworld; import com.google.tagmanager.container; import com.google.tagmanager.containeropener; import com.google.tagmanager.containeropener.opentype; import com.google.tagmanager.tagmanager; import com.google.tagmanager.datalayer; import com.google.android.gms.ads.identifier.advertisingidclient; import com.google.android.gms.ads.identifier.advertisingidclient.info; import com.google.android.gms.common.googleplayservicesnotavailableexception; import java.io.ioexception; import android.app.activity; import android.app.alertdialog; import android.content.dialoginterface; import android.graphics.color; import android.os.bundle; import android.os.strictmode; import android.util.log; import android.view.menu; import android.view.view; import android.widget.textview; import android.telephony.*; import android.provider.*; /** * {@link activity} reads background , text color local * json file , applies colors text view. */ public class mainactivity extends activity { private static final string tag = "gtmexample"; private static final string container_id = "gtm-pjnxhl"; private static final string os = "os"; private static final string device_imei = "device_imei"; private static final string device_android_id = "device_android_id"; private static final string google_ad_id = "google_ad_id"; private static string deviceimei = ""; private static string androidid = ""; private static string googleadid = ""; // set false release build. private static final boolean developer_build = true; private container container; private datalayer datalayer; private telephonymanager telephonymanager; @override protected void oncreate(bundle savedinstancestate) { if (developer_build) { strictmode.enabledefaults(); } // iau singletonul de tagmanager tagmanager tagmanager = tagmanager.getinstance(this); containeropener.containerfuture containerfuture = containeropener.opencontainer( tagmanager, container_id, opentype.prefer_non_default, null); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); telephonymanager = (telephonymanager) getsystemservice(telephony_service); // phone call may block (for timeout specified in // containeropener.opencontainer). illustration shows how utilize splash // screen avoid blocking, see cuteanimals example. container = containerfuture.get(); datalayer = tagmanager.getdatalayer(); // modify background-color , text-color of text based on value // configuration. updatevars(); } private void updatevars() { log.i(tag, "image_test"); textview textview = (textview) findviewbyid(r.id.hello_world); textview.settext(os); } public void colorbuttonclicked(view view) { log.i(tag, "colorbuttonclicked"); alertdialog alertdialog = new alertdialog.builder(this).create(); alertdialog.settitle("getting vars"); deviceimei = telephonymanager.getdeviceid(); androidid = settings.secure.getstring(getcontentresolver(), settings.secure.android_id); info adinfo = null; seek { adinfo = advertisingidclient.getadvertisingidinfo(this.getbasecontext().getapplicationcontext()); } grab (exception e) { system.out.println(e.getmessage()); } googleadid = adinfo.getid(); alertdialog.setmessage(deviceimei); datalayer.push(device_imei, deviceimei); datalayer.push(device_android_id, androidid); datalayer.push(google_ad_id, googleadid); alertdialog.setbutton(alertdialog.button_positive, "ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { } }); alertdialog.show(); updatevars(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_main, menu); homecoming true; } }

what want force deviceimei, androidid , googleadid using datalayer.

my questions are:

how test , see info pushed using datalayer? how test , see if tag has been fired info datalayer? where test see tag has been traked?

thank you!

one way utilize google analytics event info , same rule. you'll see info in ga if correct.

android google-tag-manager

No comments:

Post a Comment