Apache error logs on OSX Mavericks

So, if you are wondering why one of your php based application silently dies; its best to look at the apache error logs on OSX.

On Mavericks the last few lines of the error log can be viewed by using this command

tail -f /private/var/log/apache2/error_log

“tail” means that it will display the logs trailing at the end of the error log.

Press control + c to exit

Hope this helps someone.

Advertisements

Android Campaign/Referral Tracking with Cordova / Phonegap

I have been wrestling around for a while to get Campaign Tracking working for our games and apps. Since most of our apps are not built using native technology, we were finding it extremely difficult to access data passed to our app via the INSTALL_REFERRER broadcast receiver. Finally, with a few hacks and a lot of disappointments, we have a work around to the problem for projects built using cordova / phonegap.

Before, i start explaining how to get it going, there are a few things that you guys should be prepared with:

  1. You need to have cordova / phonegap installed with CLI (command line interface)
  2. You need ADT / Eclipse configured with latest Android SDK (i used version 19)

 

Very quickly, let me explain what i have done and get back to my project.

Here are a list of things you should do:

  1. Create a cordova project in a directory
    cordova create PROJECT_NAME
  2. Add android platform
    cordova platform add android
  3. Open/Import the android project in ADT/Eclipse – the android project can be found within (your_project_folder/platforms/android)

 

Once you have imported the project in ADT, you need to do the following:

1. Create a custom BroadcastReceiver to accept the INSTALL_REFERRER intent + context

public class CustomBroadcastReceiver extends BroadcastReceiver {
private String D_TAG = "Z-BROADCASTRECIEVER";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(D_TAG, "## CustomReceiver onReceive (context, intent)");
try {
Log.d(D_TAG, "## intent " + intent.toString());
Log.d(D_TAG, "## referrer " + intent.getStringExtra("referrer"));
Log.d(D_TAG,
"## intent.getStringExtra('referrer') "
+ intent.getStringExtra("referrer"));
String referrer = intent.getStringExtra("referrer");
postData(referrer);
} catch (Exception e) {
e.printStackTrace();
}
}
}

The doPost method, posts the referrer string to a web server to be tracked.

2. Add this custom broadcast receiver to AndroidManifest.xml

<receiver android:name="com.xyz.yourapp.CustomBroadcastReceiver" android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

This will tell the android operating system to call CustomBroadcastReceiver when the INSTALL_REFERRER intent is broadcasted.

This is all that was required. To test this solution, we need to follow the method explained by google in the link below:
Testing Google Play Campaign Measurement

Make sure, you have an emulator running or an android device connected to your computer.

From the command prompt, you need to send a modified broadcast request to the device. Make sure while doing this, the app is not open (but should be installed on the device/emulator).

Original shell command:

shell am broadcast -a com.android.vending.INSTALL_REFERRER -n your.package.name/path.to.receiver --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"

What you need to do

shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.xyz.yourapp/.CustomBroadcastReceiver --es "referrer" "referrer=testReferrer"

If you have followed all instructions to the T – then you should get the referrer value in your logcat.

Problems:

For some reason, i am unable to get the whole string passed to the broadcast receiver but only a single parameter “referrer”; this problem is also observed in the GA Campaign Tracker SDK. If anyone is able to figure this out, or the reason behind this, please let me know. This could be a problem with the adb shell command only sharing one parameter with the broadcast intent instead of the whole parameter string. Or alternatively, it could be something to do with google play being updated to latest version 3.xx

Hope this helps.