Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Ads / Firebase Integration to user identifier #487

Open
rafaeldev opened this issue Dec 9, 2024 · 0 comments
Open

Google Ads / Firebase Integration to user identifier #487

rafaeldev opened this issue Dec 9, 2024 · 0 comments

Comments

@rafaeldev
Copy link

Hi everyone!

I spend a few days searching about this integration

My PWA is delivered in the Play Store, and I am investing some money in Google Ads to find users. I created a Firebase integration on the app, and some events appear in Google Analytics.

The problem is that I can't join the user who was impacted by the campaign with my user from the system. I need to tell Google Ads, "Hey, this user with that behavior bought a product," to improve Google lead search.

I found a way to join these parts with GCLID => https://support.google.com/google-ads/answer/9744275?hl=en

image

I saw some implementation from ChatGPT but anyone make sense to me (i'm not a android developer):

import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;

import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener;
import com.android.installreferrer.api.ReferrerDetails;

public class LauncherActivity extends com.google.androidbrowserhelper.trusted.LauncherActivity {

    private InstallReferrerClient referrerClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        referrerClient = InstallReferrerClient.newBuilder(this).build();
        referrerClient.startConnection(new InstallReferrerStateListener() {
            @Override
            public void onInstallReferrerSetupFinished(int responseCode) {
                switch (responseCode) {
                    case InstallReferrerClient.InstallReferrerResponse.OK:
                        try {
                            // Captura os dados do referrer
                            ReferrerDetails response = referrerClient.getInstallReferrer();
                            String referrer = response.getInstallReferrer();
                            String gclid = Uri.parse("https://dummy.com?" + referrer).getQueryParameter("gclid");

                            if (gclid != null && !gclid.isEmpty()) {
                                System.out.println("get GCLID from Install Referrer: " + gclid);
                                // Você pode armazenar ou enviar o GCLID ao backend aqui
                                sendGclidToBackend(gclid);
                            }
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        } finally {
                            referrerClient.endConnection();
                        }
                        break;

                    case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                        System.out.println("API Install Referrer não suportada neste dispositivo.");
                        break;

                    case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                        System.out.println("API Install Referrer não está disponível no momento.");
                        break;

                    default:
                        System.out.println("Erro desconhecido na API Install Referrer.");
                }
            }

            @Override
            public void onInstallReferrerServiceDisconnected() {
                // Tente reconectar, se necessário
                System.out.println("Conexão com Install Referrer perdida.");
            }
        });
    }

    @Override
    protected Uri getLaunchingUrl() {
        // Retorna a URL original de início
        return super.getLaunchingUrl();
    }

    private void sendGclidToBackend(String gclid) {
        // Exemplo: Envie o gclid ao backend
        System.out.println("Enviando GCLID ao backend: " + gclid);
        // Você pode implementar aqui uma chamada HTTP ou outro mecanismo
    }
}

Finally, I only need to put these user identifiers at my entrypoint URL system before the browser open
`https://app.system.com?source=pwa&cglid=xpto1&client_id=xpto2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant