Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement analytics for LinkBundle and Link #89

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Api/Functions/CreateLinkBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymou
linkBundle.Provider = clientPrincipal.IdentityProvider;
}

// Set the DateTime property of the LinkBundle to the current date and time
linkBundle.CreatedDate = DateTime.UtcNow;

// Set the referrer data of the LinkBundle to the referrer data from the request headers
if (req.Headers.TryGetValues("Referer", out var referrerValues))
{
linkBundle.ReferrerData = referrerValues.FirstOrDefault();
}

try
{
var databaseName = configuration["COSMOSDB_DATABASE"];
Expand Down
13 changes: 11 additions & 2 deletions Api/Functions/GetLinkBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ public async Task<HttpResponseData> Run(
return await req.CreateJsonResponse(HttpStatusCode.NotFound, "No LinkBundle found for this vanity url");
}

var linkBundle = result.First();

// Increment the Clicks property of each Link
foreach (var link in linkBundle.Links)
{
link.Clicks++;
link.CreatedDate = DateTime.UtcNow;
jongalloway marked this conversation as resolved.
Show resolved Hide resolved
}

var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteAsJsonAsync(result.First());
await response.WriteAsJsonAsync(linkBundle);
return response;
}
}
}
}
12 changes: 11 additions & 1 deletion Client/Shared/LinkBundleDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
</button>
</div>
</div>
<div class="columns">
<div class="column">
<label class="control-label" for="createdDate">Created Date</label>
<input id="createdDate" value="@StateContainer.LinkBundle.CreatedDate.ToString("g")" class="input is-large" disabled />
</div>
<div class="column">
<label class="control-label" for="referrerData">Referrer Data</label>
<textarea rows="2" class="textarea has-fixed-size" id="referrerData" @bind="StateContainer.LinkBundle.ReferrerData" disabled></textarea>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -134,4 +144,4 @@
{
StateContainer.OnChange -= StateHasChanged;
}
}
}
2 changes: 2 additions & 0 deletions Client/Shared/LinkBundleItem.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
@link.Description
</p>
<p class="link-url">@link.Url</p>
<p class="link-clicks">Clicks: @link.Clicks</p>
<p class="link-created-date">Created Date: @link.CreatedDate.ToString("g")</p>
</div>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion Shared/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ public class Link
public string Description { get; set; }
[JsonPropertyName("image")]
public string Image { get; set; }
[JsonPropertyName("clicks")]
public int Clicks { get; set; }
[JsonPropertyName("createdDate")]
public DateTime CreatedDate { get; set; }
}
}
}
6 changes: 5 additions & 1 deletion Shared/LinkBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ public class LinkBundle
public string Provider { get; set; }
[JsonPropertyName("links")]
public List<Link> Links { get; set; } = new List<Link>();
[JsonPropertyName("createdDate")]
public DateTime CreatedDate { get; set; }
[JsonPropertyName("referrerData")]
public string ReferrerData { get; set; }
}
}
}
Loading