Skip to content

Send array of items in custom event #135

Description

@JoeriE

Hi,

I try to send a 'Started checkout' event to Klaviyo when they enter the checkout. This is my code:

                            {% for item in cart.lineItems %}
                                {% set feedProduct = {
                                    'SKU'        : item.snapshot.sku,
                                    'ProductName': item.snapshot.title,
                                    'ProductURL' : item.snapshot.url,
                                    'ItemPrice'  : item.salePrice,
                                    'ProductID'  : item.snapshot.id,
                                    'Quantity'  : item.qty,
                                    'ImageURL'  : item.snapshot.productImageUrl,
                                } %}

                                {% set feed = feed|merge([feedProduct]) %}
                            {% endfor %}

                            <form class="hidden" method="post" action="" data-form-klaviyo>
                                {{ csrfInput() }}
                                {{ redirectInput('/redirect') }}

                                <input type="hidden" name="action" value="/klaviyoconnect/api/track" />
                                <input type="hidden" name="event[name]" value="Started Checkout" />
                                <input type="hidden" name="event[Started Checkout Value]" value="{{ cart.totalAsCurrency }}" />
                                <input type="hidden" name="event[Items]" value="{{ feed|json_encode }}" />
                                <input type="hidden" name="event[CheckoutUrl]" value="{{ actionUrl(
                                    'commerce/cart/load-cart',
                                    { number: cart.number }
                                  ) }}" />
                                <input type="hidden" name="language" value="{{ craft.app.locale.id }}" />
                                <input type="text" name="email" value="">
                            </form>

The form is automatically submitted via Javascript.
The problem is that the Items array is not parsed as an array in Klaviyo. So I can't use this field as a dynamic block to show the items in my email. How to solve this?

image image

Best wishes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions