I have a Swift app with a section that contains a feed of articles. Each article is presented as a web view baked into the app.
The web views are each loaded as the links in the feed are shown, i.e. before the actual view of the article is presented.
I have noticed that Google Analytics considers these preloads to be page views. How can I avoid this? I am able to run JavaScript at the time of the preload as well as when the user navigates to the article. Is it possible to use custom JavaScript to stop GA when the page first loads, then re-enable it when the page is actually displayed?
This is not guaranteed to work but one thing you could explore, providing that you own the GA implementation and the actual articles is to filter out traffic in GA based on a query string param or a campaign param, OR to use some javascript in the articles pages to prevent the GA script from executing.
In your app, upon fetching the list of articles you would append all the URLs in the webviews with a param=value that you would use to build an exclusion rule in the property/view settings in the admin, or instruct your JS in the articles to not execute GA.
On the click on an article you would however remove the param from the URL which would cause GA to behave "normally".
From the GA console:
Related
I work with internet connected touchscreens that can run HTML projects. The HTML projects must be self contained in that all assets like scripts, css, images, videos, etc... must be in the local file structure on the hardware in case the unit loses internet connectivity. The units have a built-in web server for this basic use with a chromium browser.
I'm wanting to track events on specified DOM elements using Google Analytics so those events can be recorded when the unit has an active internet connection.
For example... If a button is clicked to perform some sort of action on the page and in that action I want to include an audit call to send that event to my GA account. Pretty standard use of this: https://developers.google.com/analytics/devguides/collection/analyticsjs/events
However, I can't seem to figure out how to make this work on a page that isn't hosted on a typical website. Everything I'm finding doesn't deal with this specific scenario and always relies on a page hosted on a typical site.
How can I track events using Google Analytics on a standalone HTML page?
Thanks,
~Mike
Can you try with sending your events by using Google Tag Manager to Google Analytics.It is quite easy to implement.
Try with adding the Google Tag Manager code, you get once you create the account in tag manager.And add your analytics property id to a custom variable in tag manager.Then create a page view type tag with analytics property id.
sample link for your reference https://support.google.com/tagmanager/answer/6102821?hl=en
Once you are able to link tag manager to your HTML page you can start tracking the page view event.Similarly, you can track other types of events.
Sorry for the basic question, but I've been reading lots on this and haven't been able to piece together a solution (as a rookie developer) so thought maybe asking would be helpful to me and others in the same boat.
I'm attempting to install GA (gtag) on a PHP site. The initialisation code works fine, Google Tag Assistant is happy, but the site functions similar to a single page application whereby the content is all loaded in dynamically via js into a DIV (little floating overlays).
I've read that creating a separate analyticstracking.php file is a best practice for the inclusion of your tracking code on pages (using include_once), but doing this on the dynamically loaded php files seems to throw up an error within tag manager – "Same web property ID is tracked twice."
My assumption was that this was happening because the page name didn't change, which would be logical, but if true, how and where does one change the page name?
Is it best to do this as an event when the nav item loading content is clicked, or is it best to somehow include tracking data in the PHP files for loaded content (and how)? If the latter, is is possible to pass the page name to the included analyticstracking.php call on load?
Or perhaps I doing this all wrong and should I be using Google Tag Manager?
Thanks in advance,
Joel
Best solution for your situation i guess will be something called "virtual pageview". Google Analytics documentation describes it here: https://developers.google.com/analytics/devguides/collection/gtagjs/single-page-applications
In shortcut:
Include Google Analytics (or GTag) code only once, for example in head.
Every additional content loading (which is key for you and want to treat as a new pageview) should send JS code with new "virtual" pageview to GA with datas seted by you (like new pageview title, new pageview url etc.).
Forget about sending events in this case as a "core". Of course you can also track events with nav clicks but first implement virtual pageviews.
I have a page I'm working on that is just a redirect page to get some browser data before sending them off to an external site. It's a white HTML page with just the google analytics code and then it redirects to Kickstarter. My problem is I don't know when I can redirect them. I want to know when the data was sent to their servers so I can redirect them. I can see how to get callback data for custom tracking, but I want all the browser data.
I see this code here: https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#hitCallback
But that seems to just be custom page view sends. Is there anyway to just do a general onload event for google analytics?
UPDATE: Some people are finding my question hard to understand. I'll try to make this simpler although I figured this was almost as simple as I could make it.
I'm doing nothing custom with Google Analytics. I just want to know when, on any page that has google analytics tracking code (the stuff you copy and paste) has loaded and sent the data up to Google. So, in theory, like ga.onload(function () { ... }). Hope that helps?
Oscar,
What's difficult to picture in your question is the navigation flow and where to pinpoint the issue:
A page redirects to a page to get some browser data before sending them off to an external site.
Google recommends placing the tracking code on the redirecting page as well as on the landing page. This way, the redirecting page will capture the actual referrer information for your reports.
Fundamentally, whenever the user hits a page with the tracking script a request to google is sent notifying about the visit. However, some browsers may actually redirect before the JavaScript call from the code can be made.
Possible solutions:
Implement your own counter inside the redirect script, separated from GA
Implement an event before the redirect happens
Implement an event on the redirect page with the useBeacon parameter
References:
https://support.google.com/analytics/answer/1009614?hl=en
track a redirect page with google analytics
I'm working on a web app which uses Backbone's HTML5 History option. In order to avoid having to code everything on the client and on the server, I'm using this method to route every request to index.html
I was wondering if there is a way to get Twitter Cards to work with this setup, as currently it can't read the page as everything is loaded in dynamically with Javascript.
I was thinking about using User Agents to detect whether it's the TwitterBot, and if it is, serving a static version of the page with the required meta-tags. Would this work?
Thanks.
Yes.
At one job we did this for all the SEO/search/facebook stuff etc.
We would sniff the user-agent, and if it was one of the following sniffers
Facebook Open Graph
Google
Bing
Twitter
Yandex
(a few others I can't remember)
we would redirect to a special page that was written to dump all the relevant data about the page for SEO purposes into a nicely formatted (but completely unstyled) page.
This allowed us to retain our google index position and proper facebook sharing even though our site was a total single-page app in backbone.
Yes, serving a specific page for Twitterbot with the right meta data markup will work.
You can test your results while developing using the card's preview tool.
https://dev.twitter.com/docs/cards/preview (with your static URL or just the tags).
I'm using google maps for a website. All the data available via the map on the home page is also listed on other pages throughout the site, but with javascript turned on these pages redirect to the home page: eg http://host.com/county/essex redirects to http://host.com/#county/essex, which makes the map load all the data for Essex.
I'd like Google to index all the pages on my site, as otherwise none of the data included in the map will be searchable. But I know that for very good reasons Google doesn't normally index pages which get redirected. Is there a way to get Google to index my pages. Or, failing that, is there a way to submit all the data to google in some other way?
*edit
All my pages are linked to from my main navigation (it's just that javascript overrides the default link action)... the upshot being that there should be no need for a sitemap as all the pages are discoverable by google bot using normal link following
Regarding submitting data to google, there is a thing called Google sitemaps that is supposed to notify google of all URIs/locations that exist on a given site and are/should be indexed. Truth is, however, that sites that aren't crawlable by default rarely benefit much from the aforementioned sitemap.
Have a look at site Maps it allows you to include urls you need indexed.
You write:
with javascript turned on these pages redirect to the home page
Google bot doesn't execute javascript. If your redirects are made in javascript, Google bot will simple index the page and ignore the redirect.