Integrate GTM snippets with AEM pages - aem

Is there any direct way to integrate Google Tag Manager JS snippets in AEM pages ?
The AEM Tools provide only for Google Analytics snippet using cloud services component. But GTM needs two code snippets on a page, one in <head> and one in <body> section of the page.
Hard coding the JS snippets in my HTML's is not a good idea.

GTM scripts is based on website specific tracking. So you can create sitelevel configurations for GTM containerID(think for future) and add header footer script in page component with dynamic containerID that you can configure in site level config so that it will be available across all pages.

Related

why is google analytics not working on website hosted on github pages?

I have my website hosted on github pages and I wanted to add Google Analytics to count views on it.
I created a Google Analytics account, created a new UA property and added full path to my website ( username.github.io/reponame/ ).
Then I added global site tag to head of my index.html ...
I waited for some time but still I can see 0 active viewers in analytics page even if I active on my website using 2 devices...
Since I found various answers about setting up analytics with Jekyll, I added Cayman theme, edited _config.yml, added _includes and did whatever said in that blog but still it didn't work ( I am not used to github actually )... So, I removed whatever changes I made for that Jekyll thing and now my repository consists of only stuff which I added in the beginning.
Why is it not working on my website ? Did I go wrong somewhere ?
How do I add Google Analytics if my repository currently consists of only index.html, css files and JS files ?
Make sure to have included {% include analytics.html %} in your website somewhere. The best practice is to put it into the head of your HTML.
Inspect your webpage, for instance with Chrome tools, to check that the script containing your Analytics ID is indeed loaded.
You should see something like:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-ZKGE3RWEMU"></script>

AEM 6.3 site map page

Is there a build in way to create a site map page. I'm not looking for a sitemap.xml generator, that we have, but a page that will list all the page named and a link.
My GoogleFu keeps bringing up the sitemap.xml generation.
Check the foundation component under '/libs/foundation/components/sitemap' you could port this functionality into a custom component for your site

Dynamic Facebook Share/Comments in Ember

After trying a few different packages to help with updating meta and og tags unsuccessfully, I am exploring other options to integrate Facebook sharing or commenting onto my Ember site. But I seem to be unable to dynamically generate the data-href value in my HBS templates.
<div class="fb-comments" data-href="http://www.whatever.com/reviews/{{model.id}}" data-width="510px" data-numposts="10"></div>
Whenever you access the first review, the comments load fine. But once you go to another, even though the href is updated the comment plugin no longer loads. Is there a way to incorporate this with dynamic URLs?

How to integrate DTM (Dynamic Tag Management) with AEM 6?

I am a newbie to Adobe DTM (Dynamic Tag Management) and have not done any kind of training related to it. However, I have been given a requirement to integrate DTM with AEM 6. I Have some requirements related to Omniture where certain events on the website are tracked and that information needs to be sent to DTM. I have followed steps described on this blog (http://blogs.adobe.com/aemtutorials/2013/07/24/customize-the-client-context/) to customize the client context by creating a new session store and storing some sample data inside it. Now, next part is to retrieve this data into DTM which I am completely unaware on how to do. What is need to achieve in particular is to create a new data element as shown in the screenshot below and write some custom java script to access the data stored inside the client context (which is present in the session store) as explained in the blog mentioned.
I have no idea on how to integrate DTM with AEM instance and how to get hold of that data needed using the script. There is no info available on the internet regarding this, hence request you to help me in case anybody have worked on such a requirement earlier. Any help is highly appreciated
Step 1 - Set up DTM cloud services configuration in AEM. You may find cloud services config at /etc/cloudservices/dynamictagmanagement.html
Step 2 - Apply the above cloud config to the root of your website using the page property. This will insert the required JS scripts and JS object into the DOM. You could also do step (1) & (2) together by manually inserting header and footer code (from DTM) into the template.
Step 3 - Supply data to DTM JS object. This you could populate the data from server side or at client side using JS. You could leverage client context as well. JS APIs available to query client context.
PS: Am also a learner on this.
Helpful links:
http://blogs.adobe.com/experiencedelivers/experience-management/integrating-dtm-custom-aem6-page-template/
http://docs.adobe.com/docs/en/aem/6-0/administer/integration/marketing-cloud/dtm.html
You can use data elements with custom script like this:
e.g. dataElement authorizableId is custom script with content
return CQ_Analytics.ClientContext.get("/profile/authorizableId");
or
dataElement pageTitle
return CQ_Analytics.PageDataMgr.getProperty("title”);
This is how I implemented it. Please note that this implementation is for integrating with flat HTML files. Where we need to add the scripts in Head tag.
Pre-requisites:
1. We need to have login credentials for DTM website.
We need to have admin rights.
We need sc3.omniture site credentials. This is usually provided by Adobe team.
From Omniture console we need to generate the AppMeasurement.js file.
From AppMeasurement.js file we need to get important details like:
a. Tracking Server Name
b. s_account name
c. Visitor namespace
Connecting HTML files to DTM:
Login to https://dtm.adobe.com with admin credentials.
Click on Project dashboard
Click on Embed tab on top navigation.
Enable Host on Akamai.
Expand Header Code widget and copy the code.
Paste that code in the tag of your HTML.
Go back to DTM again. Expand Footer Code widget and copy the code.
Paste that code to the tag of your HTML.
Configuring DTM for Direct Call Rules:
1. Go to Rules tab from top navigation.
2. Click on Direct Call Rules from left navigation now.
Click on create rule.
Give it a name in the Name section.
Expand Conditions widget.
Pay close attention to the Conditions textbox. Direct Call Rules are fired using the _satelitte.track() method, and the text you enter in the Conditions textbox will be the argument you pass in this method. We entered “change-offer-submit”, so to fire this Direct Call Rule, we will use _satelitte.track(“change-offer-submit”) as you will see in the code below.
Now use the Adobe Analytics section to set up a custom link.
Below is the code that sets up our form and its validation. Notice the way the DTM _satelitte.track() is used. Each of the arguments passed in the _satelitte.track() method matches the Condition textbox in separate DTM rules.
HTML
<div class="outer-btn">
<input class="input-btn analyticsEvent" type="button" value="Submit" data-eventName="change-offer-submit">
</div>
JavaScript
<script>
jQuery('.analyticsEvent').on('click',function() {
window.console.log('Logged Event: ' + jQuery(this).attr('data-eventName'));
_satellite.track(jQuery(this).attr('data-eventName'));
location.href='./landingPage.html';
});
</script>
This has been superseded by a tool added to DTM in the June 2016 release, ContextHub was added in 6.1 as beta, in 6.2 it reached feature parity with ClientContext. It saves a lot of time building data layers as a lot of it will be there already .

How to add Google Analytics Tracking ID to GitHub Pages

Could be a simple question but I am full of doubts right now about adding Google Analytics Tracking ID to GitHub page.
I am using GitHub automatic page generator to create my GitHub page but it asks for "Google Analytics Tracking ID". I tried to sign up with Google Analytics but there on it asks for website URL.
Now what I am supposed to do?
One more ques: can we add Google Analytics Tracking ID later on after GitHub Page has been created?
Update: Added steps descriptions for others
Solved it:
had to include username.github.io (link that I want to track) in Google Analytics website section.
you can check GitHub help page here
After that I was provided with an Tracker ID.
Note: You can easily change or add more websites on Google Analytics page from your Google Analytics admin panel.
Update 2: - Adding Google Analytics Tracking ID to Already created Github pages (As requested by #avi-aryan )
Browse to your github pages branch - which would be something like - ( https://github.com/YourUserName/YourRepository/tree/gh-pages )
Then edit index.html from listed files
Now in within HEAD tag of index.html - paste your Google Analytics Tracking ID Script ( if have already signed up for Google analytics then you can browse it under admin and then tracking info tab )
For anyone interested, if you are using Jekyll with GitHub pages, I just wrote a post showing how to correctly add Google Analytics Tracking ID to Jekyll.
You will find your Universal Analytics tracking code under Admin > Property > Tracking Info > Tracking Code.
Create a new file called analytics.html in the _includes folder found in your Jekyll website’s directory.
Add Google Analytics Tracking ID code to analytics.html.
Finally, open _layouts/head.html, and add {% include analytics.html %} just before the end </head> tag. Google recommends this placement to track all of the pages on your website correctly.
If you are using the minima template provide by Jekyll then -
Add google_analytics: UA-xxxxxxxx-x to your _config.yml
Create a file _includes/google-analytics.html and add the google analytics js code in it.
Replace
ga('create', 'UA-xxxxxxxx-x', 'auto');
with
ga('create', '{{ site.google_analytics }}', 'auto');
and you are set!
The google analytics code will now display if your site is built in production environment. For reference see the template's source code here - https://github.com/jekyll/minima
You can follow the same approach if you are using a different template by referencing the template's source code and replacing the corresponding files.
Is better to use GA-Beacon for that. GA-Beacon can track all your GitHub repo, even if the visited link isn't an html document.
Please check: https://github.com/igrigorik/ga-beacon
Adding analytics via _config.yml.
All GitHub themes (supported themes) natively support google analytics.
You just have to provide a tracking code (UA-XXXXXXXXX-X).
Google analytics comes in two flavours - Google analytics 4 (GA4), and Universal analytics. You will have to use the latter for this. GA4 will not work #.
Create a new Universal google analytics property (and not GA4 property). By default the tracking property you create will be of type GA4. You will have to select "Create a Universal Analytics property" for the property to be universal.
Once a GA4 property is created it cannot be converted to Universal property. You can only do this while creating a new property.
1.1 Turn Universal analytics on in the advanced options.
1.2 Configure Universal analytics options.
1.3 Copy the tracking ID for this newly created property.
Add this tracking ID to your gh-pages sites's _config.yml.
google_analytics: UA-XXXXXXXXX-X
The following is from modernist's readme - the theme I was using for my site.
Commit and Push the changes to github, and after few minutes navigate to your site's URL.
Verify that everything went fine.
If you search the source code now for the tracing ID, you will be able to find it.
Google analytics dashboard too will start showing activity.
The above steps show how to add google analytics to an existing gh-pages site. You can use the same code while creating a new gh-pages site too. Although it seems automatic page generator no longer exists - Can't locate "automatic page generator" button in Github
# Maybe there is a way to use GA4 natively by configuring _config.yml. I wasn't able to do that, and had to resort to universal analytics.
Reference(s)
https://www.analyticsmania.com/post/downgrade-from-google-analytics-4-to-universal-analytics/
You can add Google Analytics to a Jekyll site the same way you would any other site.
First, after setting up your Google Analytics account, navigate to the admin tab.
Next, under the accounts panel, on the left, click: Create New Account.
In Google Analytics, an account represents a set of pages that you would like to track. Set up the website's account as desired.
After your account has been created you will be sent to a page which tells you your Tracking ID and has a JavaScript snippet for you to put on the pages you would like to track. Simply put this snippet in all the pages you would like to track. Or, if you use a default layout put this snippet somewhere in it.
By the way, since you are hosting on GitHub Pages you don't need Google Analytics unless you want very detailed analytics. If all you care about is page views GitHub has this.
I use the README.md file as a source for my GitHub personal page. I also use one of the GitHub supported themes 'cayman'. No more files is required in the repository apart from _config.yml (unless you want to modify your supported theme).
To add Google Analytics, I just followed the advice in the 'cayman' repository (https://github.com/pages-themes/cayman):
Cayman will respect the following variables, if set in your site's _config.yml:
google_analytics: [Your Google Analytics tracking ID]
Full stop! Anything else! Everything works on the side of Google Analytics!
It may be a viable option for those who look for a quick set up of GitHub Pages with Google Analytics.
If you're using an automatically generated github page from your github README.md I found this to be the easiest way:
Just edit your _config.yml to look like this (with your own google analytics UA id):
theme: jekyll-theme-cayman
title: My Site
description: My site description
url: https://example.com
author: MyName
plugins:
- jekyll-seo-tag
google_analytics: UA-xxx
Then add a new file to your repository root named Gemfile with this content:
source "https://rubygems.org”
gem "github-pages", group: :jekyll_plugins
gem 'jekyll-seo-tag'
Then wait a bit and refresh your github page and show page source code. Verify that the SEO plugin has inserted your analytics java script.
More info here: https://github.com/jekyll/jekyll-seo-tag
From the installation instruction, I didn't have to add the {% seo %} in the html, luckily, because I have no html. Github seems to have thought of that.
With me, I was unable to configure Google Analytics 4 (prev Web+App) via adding google_analytics: UA-xxxxxxxx-x to your _config.yml as mentioned previously in one of the answers.
So I had to put the js recommended by the Google Analytics in the .md file.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXXX');
</script>
Anything you put in the script tag in .md will not be rendered.
Include a Global site tag in the html output <head>
Once you setup a Google Analytics account, detailed instructions are included under the "Data Streams" tab- select your data source, and then "Tagging instructions" for Global site tag(gtag.js)
Global site tag
the script will look something like this (with id replaced by XXXXXXXXXXX in my example):
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=XXXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'XXXXXXXXXXX');
</script>
Save the html script within a file in your Project directory (e.g. as "GA_script.html")
Add html file to the header
in the Rmarkdown YAML, add the reference to your specific script (see ref here):
output:
html_document:
includes:
in_header: GA_script.html
This appears to be a bug in Jekyll Minima. See these GitHub issues for reference:
feat: Support GA4 - Google Analytics 4 properties
Google Analytics data not received
Set google_analytics at _config.yml with tracing-id started with UA- rather than G-,tracing-id like G-xxxx is of Google Analytics 4. and Jekyll does not support Google Analytics 4.
Use
google_analytics: UA-xxxxxx-x
Do not use
google_analytics: G-xxxxxx
However,Google Analytics(Universal Analytics) is no longer supported by Google until 2023.7.1.