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

Fix - Change Product Clicked method on firebase_plugin #91

Merged
merged 4 commits into from
Jul 31, 2024

Conversation

edsonjab
Copy link
Contributor

Fix issue #90

@fhdeodato
Copy link

hey @edsonjab, how are you?

Thanks to invest you time and effort on this issue =)

I would like to double check with you some points

1 - If the user was in a list, we will trigger the Product List Viewed and send it to segment
this event has itemListId and itemListName

2 - if the user clicks a product, to keep the correct tracking, we should also send the itemListId and itemListName in the properties of Product Viewed

if we do not send it, I think we will lose track of which list creates the best interaction =(

so, I think the flow in the end will be something like this

1 - send the Product List Viewed

analytics.track('Product List Viewed', properties: {
  "list_id": 'hot_deals_1',
  "category": 'Deals',
  "products": [
    {
      "product_id": '507f1f77bcf86cd799439011',
      "sku": '45790-32',
      "name": 'Monopoly: 3rd Edition',
      "price": 19,
      "position": 1,
      "category": 'Games',
      "url": 'https://www.example.com/product/path',
      "image_url": 'https://www.example.com/product/path.jpg'
    },
    {
      "product_id": '505bd76785ebb509fc183733',
      "sku": '46493-32',
      "name": 'Uno Card Game',
      "price": 3,
      "position": 2,
      "category": 'Games'
    }
  ]
});

2 - Send the Product Clicked event

  analytics.track('Product Clicked', properties: {
    "list_id": 'hot_deals_1',
    "list_name": 'Hot Deals Toys'
    "product_id": '507f1f77bcf86cd799439011',
    "sku": 'G-32',
    "category": 'Games',
    "name": 'Monopoly: 3rd Edition',
    "brand": 'Hasbro',
    "variant": '200 pieces',
    "price": 18.99,
    "quantity": 1,
    "coupon": 'MAYDEALS',
    "position": 3,
    "url": 'https://www.example.com/product/path',
    "image_url": 'https://www.example.com/product/path.jpg'
  });

which should be translated to

        case 'Product Clicked':
          if (properties.containsKey('list_id') ||
              properties.containsKey('list_name') || 
              properties.containsKey('name') ||
              properties.containsKey('itemId')) {
            throw Exception("Missing properties: list_name, list_id, name and itemID");
          }

          // should we create the item object ?
          AnalyticsEventItem t = AnalyticsEventItem(itemName: properties['name'].toString(), itemId: properties['itemId'].toString());

          await FirebaseAnalytics.instance.logSelectItem(
              itemListName: properties['list_name'].toString(),
              itemListId: properties['list_id'].toString(),
              item:[clickedItem],
          );
          break;

I am not sure, havent tested it yet, but do you know if we need to create the complete object for the item array? I saw all the properties are nullable there

thanks for the help

@edsonjab
Copy link
Contributor Author

Hi @fhdeodato I got your idea,
We have defined that case about 'Product List Viewed'
image

According to firebase method logSelectItem is not necessary add all the parameters, we only include the most importants.

Maybe the confusion is because both methods logSelectItem and logViewItemList has the same parameters names itemListId and itemListName.

image
image

In your example you use product_id, this field must be mapped to itemId inside logSelectItem that is mapped on Product Clicked this is the change that I did.
image

@fhdeodato
Copy link

fhdeodato commented Jun 26, 2024

Hey @edsonjab thanks for the feedback

We have defined that case about Product List Viewed

Sure, I just used that as an example to get the navigation flow idea, first the Product List Viewed then Product Viewed, the Product List Viewed is working great =)

Maybe the confusion is because both methods logSelectItem and logViewItemList has the same parameters names itemListId and itemListName.

but as I understood from Firebase they have the same name because they will have the same value, this is not the product name or product id but the information that Firebase will use to track that the item clicked was inside of list 'X'.

that is why I think from the segment event we are missing information to keep propagating the list id and name to Firebase.

In your example you use product_id, this field must be mapped to itemId inside logSelectItem that is mapped on Product Clicked this is the change that I did.

Sorry for that, I have just copied the example from here

https://github.com/segmentio/analytics_flutter/blob/67f75d6dde982583de9689f9c947df30de9aed13/example/lib/main.dart

According to firebase method logSelectItem is not necessary add all the parameters, we only include the most importants.

Totally agree here, but if I have the information it is nice to send and get the most complete data possible =)

My point is, if we send out the itemListName and itemListId with the product clicked value we will generate relationship withe product list views that does not exist =(

because following the Firebase documentation for select_item

https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event#SELECT_ITEM()

we have the description for


ITEM_LIST_ID

The ID of the list in which the item was presented to the user (String). 

ITEM_LIST_NAME

The name of the list in which the item was presented to the user (String). 

and I also think we can add multiples items because, in some cases, user check check all the product and perform some actions

Really nice that you take time to help the community with that... thanks once again.

@edsonjab
Copy link
Contributor Author

hi @fhdeodato, so sorry for the confusion, I understand your idea.

        case 'Product Clicked':
          if (properties.containsKey('list_id') ||
              properties.containsKey('list_name') || 
              properties.containsKey('name') ||
              properties.containsKey('itemId')) {
            throw Exception("Missing properties: list_name, list_id, name and itemID");
          }

          // should we create the item object ?
          AnalyticsEventItem t = AnalyticsEventItem(itemName: properties['name'].toString(), itemId: properties['itemId'].toString());

          await FirebaseAnalytics.instance.logSelectItem(
              itemListName: properties['list_name'].toString(),
              itemListId: properties['list_id'].toString(),
              item:[clickedItem],
          );
          break;

I will implement your solution, is better to add the Item values to track the event.

@fhdeodato
Copy link

Hey @edsonjab thanks for the update =)

just one comment =)

I think we need to change the validation for the parameters

it is missing a !

so, should be like this

if ( !( properties.containsKey('list_id') ||
              properties.containsKey('list_name') || 
              properties.containsKey('name') ||
              properties.containsKey('itemId') ) ) {
            throw Exception("Missing properties: list_name, list_id, name and itemID");
          }

to validate id any of those parameters are missing =)

Thanks a lot for this fix =)

Copy link

@fhdeodato fhdeodato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change covers the correct event mapping and parameters

@MichaelGHSeg MichaelGHSeg merged commit e45c723 into segmentio:main Jul 31, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

3 participants