Affiliate Code In Google Analytics - google-analytics

With enhanced e-commerce reports, there is now a section that reports on 'affiliate code.' However I can't find how that data is populated. Is there something that needs to be pushed into the data layer using a specific attribute? Thanks!

You are probably looking for the affiliation property of a transaction. You can find it referenced in the docs here: https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#action-data
With regards to pushing it into the dataLayer (by this I assume you are using Google Tag Manager), you should add it as a key value pair in the actionField of the ecommerce.purchase object that you push into the dataLayer.
Here is the sample code that Google Docs provide that shows the use of affiliation property:
<script>
// Send transaction data with a pageview if available
// when the page loads. Otherwise, use an event when the transaction
// data becomes available.
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': 'T12345', // Transaction ID. Required for purchases and refunds.
'affiliation': 'Online Store',
'revenue': '35.43', // Total transaction value (incl. tax and shipping)
'tax':'4.90',
'shipping': '5.99',
'coupon': 'SUMMER_SALE'
},
'products': [{ // List of productFieldObjects.
'name': 'Triblend Android T-Shirt', // Name or ID is required.
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1,
'coupon': '' // Optional fields may be omitted or set to empty string.
},
{
'name': 'Donut Friday Scented T-Shirt',
'id': '67890',
'price': '33.75',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Black',
'quantity': 1
}]
}
}
});
</script>

Related

Google Analytics 4 via Google Tag Manager add_to_cart event doesn't pass the item price correctly

I'm trying to pass the add_to_cart event for my online shop to Google Analytics 4 via Google Tag Manager and I'm having an issue on the item price. Specifically, I send the following event data:
const eventData = {
event: 'add_to_cart',
ecommerce: {
items: [{
item_id: data.id,
item_name: data.title,
price: data.totalPrice,
quantity: 1
}]
}
}
When spying on it via the Google Tag Assistant I get this dataLayer value:
{
event: "add_to_cart",
gtm: {
//google stuff here
},
ecommerce: {
items: [
{
item_id: 3047,
item_name: "Something something",
price: 2.39,
quantity: 1
}
]
}
When I look at the resulting event in Google Analytics 4 via the DebugView, I get this:
item_id: 3047
quantity: 1
item_name: Something something
price: 2390000
Specifically the price is 2390000 instead of 2.39.
Any idea what could be missing here? The whole setup is pretty straightforward.
Thanks!

Can I split Google Tag Manager promotion view in many tags

I'm implementing a Google Tag Manager data layer. Until now I have most of the Enhanced Ecommerce setup successfully.
When implementing the promotion view tag, I see in all the examples that I found a single tag being pushed with a list of all the promoFieldObjects. i.e.:
dataLayer.push({
'ecommerce': {
'promoView': {
'promotions': [ // Array of promoFieldObjects.
{
'id': 'JUNE_PROMO13', // ID or Name is required.
'name': 'June Sale',
'creative': 'banner1',
'position': 'slot1'
},
{
'id': 'FREE_SHIP13',
'name': 'Free Shipping Promo',
'creative': 'skyscraper1',
'position': 'slot2'
}]
}
}
});
Happens that in my application it is way easier to push the promotions in 4 different promotion view tags, since they are rendered in groups by several different decoupled react components.
So, my question is if there is any downside in splitting this tag in multiple instead of a single big one, like:
dataLayer.push({
'ecommerce': {
'promoView': {
'promotions': [
{
'id': 'JUNE_PROMO13',
'name': 'June Sale',
'creative': 'banner1',
'position': 'slot1'
}]
}
}
});
and
dataLayer.push({
'ecommerce': {
'promoView': {
'promotions': [
{
'id': 'FREE_SHIP13',
'name': 'Free Shipping Promo',
'creative': 'skyscraper1',
'position': 'slot2'
}]
}
}
});
When you split it, I think only the last one will be "seen" by GA. This is because the second push will overwrite the "promotions" property.
I think you can get around this by keeping track of the two promotions in an array and then do an overall push.

Tracking a Checkout Step con Google Analytics Enhanced Ecommerce

Im trying to track the steps on an ecommerce site with Google Analytics, but for some reason Im not able to see the data on my checkout funnel.
I have this code:
$('#button_order_cart').click(function(e){
var currencyId = currency.iso_code;
for (var i=0; i < products.length ; i++ ){
var product = products[i];
console.log('PRODUUUCT', product);
if(product.id_product === undefined){
product.id_product = product.id;
}
ga('ec:addProduct', {
'id': product.id_product,
'name': product.name,
'category': product.category,
'price': product.price,
'currency': currencyId,
'quantity': product.quantity
});
}
ga('ec:setAction','checkout', {
'step': 1, // A value of 1 indicates this action is first checkout step.
});
// Check if we're logged in and automatically send checkout step step number 2.
if(cart.id_customer !== null && cart.id_customer !== '0'){
for (var i=0; i < products.length ; i++ ){
var product = products[i];
ga('ec:addProduct', {
'id': product.id_product,
'name': product.name,
'category': product.category,
'price': product.price,
'currency': currencyId,
'quantity': product.quantity
});
}
ga('ec:setAction','checkout', {
'step': 2,
'option': 'Logged In'
});
}
});
And on the GA Debugging console Im getting this output when clicking the button:
VM7378 analytics_debug.js:10 Executing Google Analytics commands.
VM7378 analytics_debug.js:10 Running command: ga("ec:addProduct", {id: 1728, name: "24 Rosas - First Red", category: undefined, price: "Q. 348.00", currency: "GTQ", quantity: 2})
VM7378 analytics_debug.js:10 Executing Google Analytics commands.
VM7378 analytics_debug.js:10 Running command: ga("ec:setAction", "checkout", {step: 1})
Im not sure why I cant see the data if the Analytics debugging console throws no errors.
Can anyone help me verify if Im calling the right actions?

Cannot log productClick events in GA eCommerce Enhanced and Tag Manager

I've set up GA eCommerce Enhanced via dataLayer on my website. All GA ecommerce reports work properly except one. GA doesn't log productClick event(
data are pushed to dataLayer by execution of next functions
function eProductClick(product) {
dataLayer.push({
'event': 'productClick',
'ecommerce': {
'click': {
'actionField': {'list': product.list},
'products': [{
'id': product.id,
'name': product.name,
'price': product.price,
'category': product.category,
'position': product.position
}]
}
},
});
}
function eAddToBasket(product) {
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'UAH',
'add': {
'products': [{
'id': product.id,
'name': product.name,
'price': product.price,
'category': product.category,
'quantity': 1
}]
}
}
});
}
Both events are cought by tag manager
I realy can't find the reason why GA doesn't track Product Views
It looks like the event that is not working/missing is the product details action.
https://developers.google.com/tag-manager/enhanced-ecommerce#details
In the report you are looking at the number of product views is not calculated by the number of product click actions but the number of product detail actions. It makes sense as a user could land on a product details page and you would still want that tracked as a product detail view.

How to record multiple transactions with GA's Enhanced Ecommerce

When customers place orders on our system, they can be buying from one of several different "stores". We have a consolidated Shopping Cart experience, but split the transaction into individual orders as the final step.
I need some way to, on the final "thank you" page of the check out funnel, add products and record a transaction multiple times.
Does setting an action of "purchase" effectively clear the products so I can add more and repeat the process? For example...
ga('ec:addProduct', { 'id': '1' });
ga('ec:addProduct', { 'id': '2' });
ga('ec:setAction', 'purchase', { 'id': '123456' });
ga('ec:addProduct', { 'id': '3' });
ga('ec:setAction', 'purchase', { 'id': '987654' });
...In the above scenario, will Transaction 123456 contain products 1 & 2, while Transaction 987654 contains only product 3? Or, will Transaction 987654 contain products 1, 2, & 3?
Appreciate any insight into this!
Best,
Nate
You have to split the transactions by sending an event between them, this hit will send all the information so you can start over with the next transaction.
ga('ec:addProduct', { 'id': '1' });
ga('ec:addProduct', { 'id': '2' });
ga('ec:setAction', 'purchase', { 'id': '123456' });
ga('send','event','whatever',{'non-interaction': 1});
ga('ec:addProduct', { 'id': '3' });
ga('ec:setAction', 'purchase', { 'id': '987654' });
ga('send','event','whatever',{'non-interaction': 1});

Resources