Add UTM parameter based on events - javascript

I know that it's best to add Google Analytics UTM parameters externally for incoming campaign traffic.
However, when dealing with a juggernaut of an IT team who like to say "no" a lot I'd like to attempt to arm myself with a solid response. Analysts will feel my pain in trying to convince others to track campaigns the correctly, rather than by listening to a non analytics users advice of just creating segments based on URLs.
There will be a campaign running where a visitor to the website will input a promo code in order to get a free thing.
For whatever reason we cannot tag the incoming traffic or the links that will lead from the promo source with our UTM parameters.
I can create an event in GA for when a visitor enters a promo code that relates to the campaign in question - the URL generated will contain the promo code int he URL, thus allowing me to create an event.
Is it possible in Google-Analytics, combined with a lateral thinking developer, to overwrite the UTM parameters based upon a click event halfway through the visitor session? Could a script do this?
Any other ways around it?
We do have Google-Tag-Manager at our disposal too.

Doug,
Sorry to dissapoint you, but any overwriting based on events (or any single-hit action by user) won't work correctly and would lead to skewing your data anyway. See this brilliant post by Joshua.
What you could do however is to use CustomVar or CustomDimension (on session level probably), which would substitute UTM parameters. So if there is a promo on your werbsite, you can assign some value after users click on it.
Then by building a custom report, you should be able to use this with no restrictions, just instead of medium/source pick your customvar/customdim.
Hope this helps.

Related

Hubspot and Google Analytics - Pass session source and medium information

I’m trying to pass session source and medium information into HubSpot so that if a form is filled out / some other conversion event happens, I can tell where that specific session started.
From the HubSpot side, this should be a two-field solution — e.g. the session and medium get passed across into fields that update with each new visit. If a form gets filled out, it will copy the session and medium data across to more permanent fields.
The end result of this process will mean that I’ll be able to say “we got 100 people to download our ebook this month. 8 came from email, 70 came from organic search, and 22 came from social media”.
All I can say right now is “we got 100 people to download our ebook. I have no idea where they’re from.”
I would like to know if this would be possible to do using Google Analytics and Hubspot as well as some script.
Upon researching I have found these two scripts that may be relevant to this:
https://github.com/troyfawkes/dgacquisition
and this:
http://sbjs.rocks/#/
Any help would be greatly appreciated.
sbjs works great for this if all your campaigns have proper utm tags.
However, you might have set this up the other way and send a specific event to Google Analytics each time a user fills a specific form. then you can set up a goal for that event and use Acquisition reports to answer your exact question "where my conversions come from?"

Google analytics - difference between analytics data and the data from the core platform

We use Google analytics with Google Tag manager for our ecommerce platform based to track the conversion, etc.,
In the thank you page, its used to track the order value and the revenues.
Consistently we see a difference of about 15 to 20 % difference between GA data and the data from the core platform.
Tried to find a pattern among the missed orders but couldn´t ascertain one easily. The GA recorded orders include devices like Desktop, tablet and mobile and we see different browsers too.
Need inputs to analyze this better.
Note: Thank you page is loaded by a redirect from the payment gateway system
15-20% difference is not good at all. Google says you should expect better than 95% accuracy, and to keep at it if you're not getting those numbers.
Note: The more "techy" crowd that your website has, the more folks you'll run into "Do not track" or with Ad-Blocking tech in their browser. Normally, you'd want to try to baseline that difference using device category filters to see if the gap is bigger for desktop (most phones/tablets don't use ad-blocking).
First, question. If the user lands on the thankyou page, and hits the refresh button, does it send another "conversion" to GA? IF so, you want to make sure that you build in logic that prevents duplicate conversions to be sent if the user was not making duplicate purchases. A browser refresh is not a purchase, don't record it as such.
Second, if the page takes forever to load, or you have users that have bad internet, then that could increase the difference. They might be closing the browser or exiting site before GA client has a chance to send the final conversion to the server. So how is the performance of your thankyou page?
Are you sure you're looking at the correct business data? I've been told GA numbers are off by the business before and it turned out they messed up their own query in the transaction system (and they had been doing so for years!). It is a long shot, but if you feel super confident about your GA measurement setup, then run it by the folks giving you the transaction numbers.
Finally, if you can't get the difference down then move to the Measurement Protocol server-side implementation of GA. You simply need to record the IP address of the user and their GA client id, and then construct an HTTPS GET request using the Measurement Protocol fields for a valid hit. Server side measurement is the most accurate way to do this, but requires code updates in the ecommerce platform itself.

Implementing CPA affiliate purchases in GTM enhanced ecommerce

I'm implementing Enhanced Ecommerce on our (mainly affiliate) website through GTM. We have list views and detail views etc.. so implementing impressions and clicks is easy, but for affiliate purchases there is a problem.
We have two payment models for the shops that are showing their products on our site:
Cost per Click. I can implement a small purchase on the clickout page.
Cost per Acquisition. Here is the problem: The purchases are made on a different website on a different time. Using PHP API's I get the purchases made a few times a day through a cronjob.
How can I create a purchase (preferably using PHP, using javascript is messy on a cronjob) but retain the cookie value so I can link the purchase to the clickout and channel people used to get on our site.
I thought of creating all zero purchases for each clickout and maybe repurchase using the same transaction ID. This might work, but we will end up with thousands of empty purchases.
I ran across a similar problem a while back. Our checkout lives on a different domain. So when Adwords people would checkout after migrating to Universal, I was losing that data at checkout. I think my solution there could help you. This all assumed you're using Universal Analytics and not the old deprecated libraries.
The first thing I do is grab the GA cookie, which is named _ga. Inside it is your GA session. It looks like this (it will be much longer)
GA1.2.3456.7890
The third and fourth number sets (including the period) are the session itself. Parse them out.
Now you want to find some way to store this with the user. I used my PHP session (we pass it in the query string when we jump domains) and stored it there. You'll have to figure something out that works for you here.
On the other site we need to specify the GA session and site within the GA block. Please note that the new site will report these visits as if they belonged to the original site. The UA-XXXX-Y should be from the original site and yourdomain.com should be the new site TLD
ga('create', 'UA-XXXX-Y', { 'cookieDomain': 'yourdomain.com', 'clientId': '3456.7890' });
Now you can pass your purchase metrics in. When a session converts on the new site, the old site will track it, along with any other things that session held (i.e. page impressions, Adwords clicks, etc.). You don't need any messy cron jobs to do this. Just be aware, as I said earlier, that these page visits belong to the original site as far as GA goes. You could try reporting two sets of metrics to get around this, but I have not tried that.
Reading the comment beneath the answer from Machavity, i assume that you are using Universal Analytics, or else Universal Analytics is the way to go!
I have had a case in the past where we had to think of a one way tracking system because we didn't have access to the other site's code.
Give a look at the Google Measurement protocol. This protocol makes it possible to send raw userdata directly to google analytics over HTTP.
Link to Google measurement protocol

Prevent accidental session hijacking using JavaScript

Okay, this may sound like a stupid question, but this actually is a real life situation I gotta sort out.
The company I work for is using a rather outdated online shop software (PHP) which is hosted on the companys server. Unfortunately, the source code is encrypted and the CMS does not allow me to add some PHP code either, so I guess I'm stuck with JavaScript on this one.
Let's say we have a huge sale start coming up and people start sharing links via YouTube, Twitter, and so on. Due to the software being made somewhere in the last century, some links still contain session IDs which will definitely be shared by some users. This, however, will result in multiple users placing orders on the same customer account or even worse, overwriting existing customer accounts with new customer data.
I know that this situation is far from ideal and that the software definitely needs and update, but this is not an option at the moment. I also know that I'm not getting a 100% solution, so I'm just gonna try to prevent people from accidentally wrecking some customer data.
That being sad, I though about checking the URL for a Session ID and checking the value in document.referrer aswell. If the URL contains a Session ID and the referrer is some other server than ours, I'll just do a quick redirect to the main landing page. Again: This is meant to prevent the average user from accidentally logging into someone elses account due to clicking on a bad link, I'm not trying to prevent proper session hijacking here.
Any ideas on this one? Are there any situations where the referrer might not contain actual values, e. g. the browser not sending referrers at all? Any other ways to sort this out using JavaScript only?

How would I capture the timestamp of when a link is clicked in an Email?

This may be a bit of a tricky one (for me at least, but you guys may be smarter). I need to capture the timestamp of exactly when a reader clicks a link in an email. However, this link is not a hyperlink to another webpage. It is a link formatted as a GET request with querystrings that will automatically submit a form.
Here is the tricky part....The form processing is not handled by PHP or .NET or any other server side language. It is a form engine that is hosted and managed by a cloud based marketing platform that captures and displays the form submission data (So i have no access to the code behind the scenes).
Now, if this wasn't an email I'd say it is simple enough to just use Javascript. However, javascript doesn't work so well with email, if at all (I'm just assuming there are some email clients out there that support javascript).
How would you go about capturing the timestamp for when the link is clicked without using any type of scripting? Is this even possible?
The best solution i could come up with was to have the link point to an intermediate page with javascript to capture timestamp and then redirect to the form submission. Only problem with that is that it will only capture timestamp of page load and not of the actual click activity.
There is no way to do what you want "without any type of scripting". If no scripting is done, no functionality may be added or changed.
The best option is the very one you suggested: use an intermediary page that records the request time. Barring unusual circumstances (such as a downed server), the time between a link being clicked and the request reaching the server will be less than 1 second.
Do you really need a higher resolution or accuracy than ~1s? What additional gain is there from having results on the order of milliseconds or microseconds? I can't imagine a scenario in which you'd have tangible benefits from such a thing, though if you do have one I'd love to hear it.
My initial thought was to say that what you're trying to do can't be done without some scripting capability, but I suppose it truly depends on what you're trying to accomplish overall.
While there is ambiguity in what you're trying to accomplish from what you have written, I'm going to make an assumption: you're trying to record interaction with a particular email.
Depending on the desired resolution, this is very possible--in fact--something that most businesses have been doing for years.
To begin my explanation of the technique, consider this common functionality in most mail clients (web-based or otherwise):
Click here to display images below
The reason for this existing is that the images that are loaded into the message that you're reading often come from a remote server not hosted by the mail client. In the process of requesting that image, a great deal of information about yourself is given to that outside server via HTTP headers in your request including, among other things, a timestamp for the request. Thus the above button is used to prevent that from happening without your consent.
That said, its also important to note how other mail client providers, most notably gmail, are approaching this now. The aforementioned technique is so common (used by advertisers and by other, more nefarious parties for the purpose of phishing, malware, etc) that Google has decided to start caching all mail images themselves. The result is that the email looks exactly the same, but all requests for images are instead directed at Google's cached versions.
Long story short, you can get a timestamp to note interaction with an email via image request, but such metric collection in general, regardless if its done in the manner I've outlined, is something mail clients try to prevent, at least at some level.
EDIT - To relate this back to what you mention in your question and your idea of having some intermediary page, you could skip having that page and instead you would point an image request towards a server you control

Categories