Analytics
3.6K members online now
3.6K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Tracking dynamic values for Ecommerce

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'm currently trying to setup revenue tracking with eCommerce but I'm having some issues figuring out how to make it work for our company.   It's an insurance company so that means that the prices per policy can differ quite a bit.   We're using C# with Razor and Knockout.js so I'm not sure what the approach would be for this. I've got eCommerce turned on within the property and the code snippet inserted onto our confirmation page for checkout.  It's also noted that I've tested some static values within the code onto a test property and it transmits normally.
 This is my first time diving into Google Analytics so i apologize for any details left out.  Let me know if I can provide any more info to help understand my situation.  

 

 

Tracking dynamic values for Ecommerce

Explorer ✭ ✭ ☆
# 2
Explorer ✭ ✭ ☆

No worries Travis, the product price (and of course the transaction value) can differ for each sale. The same product can have different prices. Just set the price field to whatever insurance premium value you have.

Tracking dynamic values for Ecommerce

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Sorry but I don't believe I understand what you mean, or vice versa.  I need to have the price for the item change each time a user checks out with a plan.  The premiums can change so much depending on conditions and what not.  I'd also be putting in so many "addItem" objects that it would record all of them and not just the one that the customer is checking out with.  

Tracking dynamic values for Ecommerce

Explorer ✭ ✭ ☆
# 4
Explorer ✭ ✭ ☆

Are (a) all items of the policy considered different products, and the combination of those options ultimately becomes the policy? Or (b) do you track a policy as a single product with a price that might change for every unique transaction?

 

If (a), you need to populate the transaction with the proper products (and their price, even if different in each case) only when the user confirms the policy.

 

If (b), then you need to send only one product with whichever price is appropriate.

 

In both case, GA doesn't care if the price for a product varies every time.

 

You probably shouldn't do a addItem every time an option is changed... at best, track those as "add to cart" and track the corresponding "remove from cart" to have a better idea of which options are being considered. Track only "final" options when the user proceed to the purchase.

Tracking dynamic values for Ecommerce

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

I'd say that we're doing (a).  And while I understand the logic behind your answer, thanks for that, I guess what i'm really looking for is an actual code example that someone can point me towards that will help me out.  The examples that are given in the Google documentation only account for PHP, nothing else.  Also all examples I've seen have a string value and not a call to the dynamic data.  Considering that I'm using C# I would expect me to be able to reference the model on my confirmation page in regards to the premium and product type.

Tracking dynamic values for Ecommerce

Explorer ✭ ✭ ☆
# 6
Explorer ✭ ✭ ☆

Travis, please allow me to ask: are you a web developer? Do you have any development experience?

 

What you are asking really fall in the realm of web development and isn't GA specific.

I'm afraid I won't be able to help you beyond this point. This pertains to C# development and not GA tracking itself. Note that the string value can simply be replaced by a function call which will retrieve the dynamic value - and this is unique to your application. A C# programmer should be able to understand the PHP examples. The specifics of how you get the dynamic values pertains to C# development and your specific website application.

 

Maybe someone else can chime in?

Tracking dynamic values for Ecommerce

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

That would be a yes to both of your questions there.  Sorry if that wasn't clear from the beginning. I assumed since I was in the "Code Implementation" section of the forum that it was the right place to ask.  I'm new to C# and know much of nothing about PHP.  Anyways, I'd really like for someone else to possibly be able to point me in the right direction of an example or tutorial that doesn't involve PHP.  

Re: Tracking dynamic values for Ecommerce

Explorer ✭ ✭ ☆
# 8
Explorer ✭ ✭ ☆

Yeah, sorry I can't help you much here - haven't developed in C# for years.

But remember, at the end of the day, be it C# or PHP, the server-side code needs to generate a client-side JavaScript snippet of code that will be injected on the page and understood either by GTM (preferable) or GA, and executed client-side.

 

From the C# code, to trigger a purchase with GTM, the generated JavaScript code will need to look like this. If the site is using GA, the generated code needs to look like this.

 

I don't know much about C#, but in essence, you would build the JS script block dynamically and use the C# RegisterClientScriptBlock() to inject it on the page.

 

Where you are setting the price, you would do something like this:

 

 

ClientScriptManager cs = Page.ClientScript;
...
String generatedDataLayer = "dataLayer.push(... refer to example code block... ";
generatedDataLayer.append("'price': ");
generatedDataLayer.append(yourFunctionToRetrivePrice());
generatedDataLayer.append(", ... rest of dataLayer");
...
cs.RegisterClientScriptBlock(cstype, csname, generatedDataLayer.ToString(), false);

 

 

I have no clue if this will work - but it's an idea Smiley Wink

Tracking dynamic values for Ecommerce

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

No worries Stéphane, I appreciate all of the replies and this snippet could point me in the right direction.  Going to have a sit down with my boss who is a back-end engineer and he'll be able to let me know if this is what we could use.   

 

Thanks again!  I'll update this thread as soon as I can with my progress into the issue.