Skip to content

Commit

Permalink
add basic ga tag w/ settable campaignid (#15157)
Browse files Browse the repository at this point in the history
Co-authored-by: scbedd <[email protected]>
  • Loading branch information
azure-sdk and scbedd authored Jul 27, 2021
1 parent 8cfd3cc commit 3fca53b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
28 changes: 19 additions & 9 deletions eng/common/docgeneration/Generate-DocIndex.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Get-BlobStorage-Artifacts($blobStorageUrl, $blobDirectoryRegex, $blobAr
$blobStorageUrlPageToken = $blobStorageUrl + "&marker=$pageToken"
$resp = Invoke-RestMethod -Method Get -Uri $blobStorageUrlPageToken
}
# Convert to xml documents.
# Convert to xml documents.
$xmlDoc = [xml](removeBomFromString $resp)
foreach ($elem in $xmlDoc.EnumerationResults.Blobs.BlobPrefix) {
# What service return like "dotnet/Azure.AI.Anomalydetector/", needs to fetch out "Azure.AI.Anomalydetector"
Expand All @@ -39,8 +39,8 @@ function Get-BlobStorage-Artifacts($blobStorageUrl, $blobDirectoryRegex, $blobAr
} while ($pageToken)
return $returnedArtifacts
}
# The sequence of Bom bytes differs by different encoding.

# The sequence of Bom bytes differs by different encoding.
# The helper function here is only to strip the utf-8 encoding system as it is used by blob storage list api.
# Return the original string if not in BOM utf-8 sequence.
function RemoveBomFromString([string]$bomAwareString) {
Expand All @@ -55,8 +55,8 @@ function RemoveBomFromString([string]$bomAwareString) {
}
return $bomAwareString
}
function Get-TocMapping {

function Get-TocMapping {
Param (
[Parameter(Mandatory = $true)] [Object[]] $metadata,
[Parameter(Mandatory = $true)] [String[]] $artifacts
Expand Down Expand Up @@ -87,10 +87,10 @@ function Get-TocMapping {
}
$orderServiceMapping[$artifact] = @($serviceName, $displayName)
}
return $orderServiceMapping
return $orderServiceMapping
}

function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) {
function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang, [String]$campaignId = "UA-62780441-46") {
LogDebug "Start generating the docfx toc and build docfx site..."

LogDebug "Initializing Default DocFx Site..."
Expand All @@ -100,6 +100,15 @@ function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) {
LogDebug "Copying template and configuration..."
New-Item -Path "${DocOutDir}" -Name "templates" -ItemType "directory" -Force
Copy-Item "${DocGenDir}/templates/*" -Destination "${DocOutDir}/templates" -Force -Recurse

$headerTemplateLocation = "${DocOutDir}/templates/matthews/partials/head.tmpl.partial"

if ($campaignId -and (Test-Path $headerTemplateLocation)){
$headerTemplateContent = Get-Content -Path $headerTemplateLocation -Raw
$headerTemplateContent = $headerTemplateContent -replace "GA_CAMPAIGN_ID", $campaignId
Set-Content -Path $headerTemplateLocation -Value $headerTemplateContent -NoNewline
}

Copy-Item "${DocGenDir}/docfx.json" -Destination "${DocOutDir}/" -Force
$YmlPath = "${DocOutDir}/api"
New-Item -Path $YmlPath -Name "toc.yml" -Force
Expand All @@ -109,7 +118,7 @@ function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) {
$artifact = $serviceMapping.Key
$serviceName = $serviceMapping.Value[0]
$displayName = $serviceMapping.Value[1]

$fileName = ($serviceName -replace '\s', '').ToLower().Trim()
if ($visitedService.ContainsKey($serviceName)) {
if ($displayName) {
Expand Down Expand Up @@ -145,7 +154,7 @@ function GenerateDocfxTocContent([Hashtable]$tocContent, [String]$lang) {
& $($DocFx) build "${DocOutDir}/docfx.json"
# The line below is used for testing in local
#docfx build "${DocOutDir}/docfx.json"
Copy-Item "${DocGenDir}/assets/logo.svg" -Destination "${DocOutDir}/_site/" -Force
Copy-Item "${DocGenDir}/assets/logo.svg" -Destination "${DocOutDir}/_site/" -Force
}

function UpdateDocIndexFiles {
Expand All @@ -166,6 +175,7 @@ function UpdateDocIndexFiles {
# Update main.js package regex and replacement
$mainJsContent = $mainJsContent -replace "var PACKAGE_REGEX = ''", "var PACKAGE_REGEX = $packageRegex"
$mainJsContent = $mainJsContent -replace "var PACKAGE_REPLACEMENT = ''", "var PACKAGE_REPLACEMENT = `"$regexReplacement`""

Set-Content -Path $MainJsPath -Value $mainJsContent -NoNewline
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>{{#title}}{{title}}{{/title}}{{^title}}{{>partials/title}}{{/title}} {{#_appTitle}}| {{_appTitle}} {{/_appTitle}}</title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="{{#title}}{{title}}{{/title}}{{^title}}{{>partials/title}}{{/title}} {{#_appTitle}}| {{_appTitle}} {{/_appTitle}}">
<meta name="generator" content="docfx {{_docfxVersion}}">
{{#_description}}<meta name="description" content="{{_description}}">{{/_description}}
<link rel="shortcut icon" href="{{_rel}}{{{_appFaviconPath}}}{{^_appFaviconPath}}favicon.ico{{/_appFaviconPath}}">
<link rel="stylesheet" href="{{_rel}}styles/docfx.vendor.css">
<link rel="stylesheet" href="{{_rel}}styles/docfx.css">
<link rel="stylesheet" href="{{_rel}}styles/main.css">
<meta property="docfx:navrel" content="{{_navRel}}">
<meta property="docfx:tocrel" content="{{_tocRel}}">
{{#_noindex}}<meta name="searchOption" content="noindex">{{/_noindex}}
{{#_enableSearch}}<meta property="docfx:rel" content="{{_rel}}">{{/_enableSearch}}
{{#_enableNewTab}}<meta property="docfx:newtab" content="true">{{/_enableNewTab}}

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_CAMPAIGN_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'GA_CAMPAIGN_ID');
</script>
</head>

0 comments on commit 3fca53b

Please sign in to comment.