user3465554
user3465554

Reputation: 39

How can I use custom variable for product impression instead of enhanced ecommerce datalayer?

I got a request where we need to create custom javascript variable to send product impression instead of enhanced ecommerce datalayer. Can someone please help me understand how that can be achieved by pointing me in correct direction?

TIA

Upvotes: 1

Views: 883

Answers (2)

sdhaus
sdhaus

Reputation: 1896

To expand on the answer above, your analyst just wants the product array saved to a variable, rather then pushed through a dataLayer push.

For example:

Instead of:

dataLayer.push({
  'ecommerce': {
    'currencyCode': 'EUR',                       // Local currency is optional.
    'impressions': [
     {
       'name': 'Triblend Android T-Shirt',       // Name or ID is required.
       'id': '12345',
       'price': '15.25',
       'brand': 'Google',
       'category': 'Apparel',
       'variant': 'Gray',
       'list': 'Search Results',
       'position': 1
     },
     {
       'name': 'Donut Friday Scented T-Shirt',
       'id': '67890',
       'price': '33.75',
       'brand': 'Google',
       'category': 'Apparel',
       'variant': 'Black',
       'list': 'Search Results',
       'position': 2
     }]
  }
});

They want:

var productArray =[{
   'name': 'Triblend Android T-Shirt',       // Name or ID is required.
   'id': '12345',
   'price': '15.25',
   'brand': 'Google',
   'category': 'Apparel',
   'variant': 'Gray',
   'list': 'Search Results',
   'position': 1
 },
 {
   'name': 'Donut Friday Scented T-Shirt',
   'id': '67890',
   'price': '33.75',
   'brand': 'Google',
   'category': 'Apparel',
   'variant': 'Black',
   'list': 'Search Results',
   'position': 2
 }]

This means they can selectively fire the different products per event, rather then relying on the dataLayer push itself. This can be useful for product impression tracking.

Upvotes: 0

Igneel64
Igneel64

Reputation: 618

Your question is certainly unclear but I will try to give you some options. First if it is the kind of use-case you are looking for because the product impression data are not in the dataLayer and you just want to fetch them from somewhere else, the solution is described in this Simo Ahava blog post. If the reason is that you cannot use the GTM tags to send your product impressions, I would advise you use either the custom Javascript or custom HTML tag to implement your script. That script would get in any way the product data for your page and then use the manual ga() command as described here. But here is the catch. If you try to send this in a page where GTM is implemented you will get an error: 'Command ignored. Unknown target: undefined'. That is because GTM uses it's own tracker names to send data to GA. To implement your own tracking along with GTM on the same page you should make some changes or additions to your code to be able to get the correct tracker name. How to do that imo is not easy but one way is described in this article

Upvotes: 1

Related Questions