package fiftyfive.and_testFacebookAnalytics;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Spinner;
import android.widget.Toast;


import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.google.firebase.analytics.FirebaseAnalytics;


public class MainActivity extends AppCompatActivity {

    //private FirebaseAnalytics mFirebaseAnalytics ;
    Spinner catalogue;
    Cart cart = new Cart();
    Bundle bundle4cart = cart.transformCartToBundle();

    Bundle FBTagParameters = new Bundle();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Track automatically AppInstalls and AppOpens
        FacebookSdk.sdkInitialize(getApplicationContext());
        //AppEventsLogger.activateApp(this);

        //Create an instance of FB Analytics logger
        AppEventsLogger logger = AppEventsLogger.newLogger(this);

        track_screenView(logger);


    }




    //méthode pour faire partir un event après avoir cliqué sur un bouton
    //event codé pour utilisation via GTM et envoyé sur GA
    public void track_event(View v, AppEventsLogger logger) {
        FBTagParameters.clear();
        FBTagParameters.putString("eventCategory", "clic");
        FBTagParameters.putString("eventAction", "fire");
        FBTagParameters.putString("eventLabel", "click2GA_GTM");
        logger.logEvent("eventClick", FBTagParameters);
        Log.d("TAG: ", "track_event.");
        Toast.makeText(getApplicationContext(), "track_event sent.", Toast.LENGTH_SHORT).show();


    }


    //View product list
    public void viewProductsList(View v){
        Intent zeIntent = new Intent(MainActivity.this, ProductsListActivity.class);
        zeIntent.putExtra("cart", bundle4cart);
        startActivityForResult(zeIntent, 0);
    }


    @Override
    public void onStart() {
        super.onStart();


    }


    public void track_screenView(AppEventsLogger logger){

        FBTagParameters.clear();
        FBTagParameters.putString("screenName", "HomePage");
        logger.logEvent("screenView", FBTagParameters);
        Log.d("TAG: ", "screenView - HomePage sent.");
    }

    @Override
    public void onStop() {
        super.onStop();
    }
}

@@ -983,127 +983,8 @@
 );%0A%0A
-        //Create an instance of FB Analytics logger%0A        AppEventsLogger logger = AppEventsLogger.newLogger(this);%0A%0A
     
@@ -1004,22 +1004,16 @@
 eenView(
-logger
 );%0A%0A%0A   
@@ -1190,35 +1190,164 @@
 ew v
-, AppEventsLogger logger) %7B
+) %7B%0A        //Create an instance of FB Analytics logger%0A        AppEventsLogger logger = AppEventsLogger.newLogger(this);%0A        //Set the event parameters
 %0A   
@@ -1555,24 +1555,48 @@
 k2GA_GTM%22);%0A
+        //Log the event%0A
         logg
@@ -2152,33 +2152,163 @@
 iew(
-AppEventsLogger logger)%7B%0A
+)%7B%0A        //Create an instance of FB Analytics logger%0A        AppEventsLogger logger = AppEventsLogger.newLogger(this);%0A        //Set the event parameters
 %0A   
@@ -2394,24 +2394,48 @@
 HomePage%22);%0A
+        //Log the event%0A
         logg

fix the bug on event fire